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?
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