As I mentioned in the previous post, I have a need for Topshelf services to run in separate application domains. This is a feature I have wanted for a little while, but had no idea how to do it. Thanks to some help from Oren I now have a first pass at an ‘Isolated Service’. You can try them out your self by configuring your service like:
RunnerConfigurator.New(x =>
{
x.SetDisplayName("chris");
x.SetServiceName("chris");
x.SetDescription("chris's pants");
x.ConfigureServiceInIsolation(c=>
{
c.WithName("my_service");
c.WhenStarted(s => s.Start());
c.WhenStopped(s => s.Stop());
c.WhenPaused(s => { });
c.WhenContinued(s => { });
});
});
Important Note: the ‘WithName’ which used to be for display purposes has been repurposed to be the services IoC handle. Since this is a required thing I am thinking I will put it up in the method parameter list for ConfigureServiceInIsolation. I had realized that I was using ServiceLocator.GetInstance() which could make it very hard to get the one specific instance you want so I changed it to ServiceLocator.GetInstance(name) to make it easier. I am not super happy with this at the moment and would love some feedback on it.
This is my first time doing AppDomain programming so any thoughts would be very much appreciated (just search for the word ‘Isolated’ in the code base).
-d