How do you dispose of a service you provide?


#1

When consuming a service you can return a Disposable to stop using the service if it shuts down.

What is the correct way to handle this from the provider side?


#2

A package is considered to be the provider of a service. The lifetime of the service is assumed to be the lifetime of the package. If the package has been activated but not deactivated, the service should be available. From there, the package’s deactivate method is how one should clean up for a service.


#3

ok, that makes sense. For what I’m working on I don’t have any need to hold on to a reference to the service I provided, so my provider is just constructing a new object and returning it. I guess now I need to hold a reference so I can shut it down on deactivate


#4

You might want to take a look at the status-bar package and see how they handle providing the status bar service.