Slobo80
Slobo80

Reputation: 188

Best way to clean up resources in StatefulService

I have a services activated in shared process model. My service base class extends StatefulService class like this:

public class MyStatefulService : StatefulService, IDisposable
{
   public StatefulServiceBase(
     StatefulServiceContext serviceContext,
     IReliableStateManagerReplica2 reliableStateManagerReplica)
   : base(serviceContext, reliableStateManagerReplica)

   public void Dispose()
   {
       // my cleanup code
   }
}

I noticed that Service Fabric never calls Dispose() method in my class. Is there a different approach for disposing/cleaning up resources?

Upvotes: 0

Views: 17

Answers (1)

Peter Bons
Peter Bons

Reputation: 29711

There is no support for IDisposable, there is a ticket for it but it is still open.

You can override the StatefulServiceBase.OnCloseAsync() method and cleanup there or act on the cancellation request of the cancellation token passed to RunAsync().

The full lifecycle is documented here

Upvotes: 0

Related Questions