Topshelf Isolated Services

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

About Dru Sellers

Sr. Software Engineer at Dovetail Software.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Alexey Ivanov

    I’ve got the same problem like Andreas. Is there any resolution or workaround?

    Thanks in advance,
    Alexey

  • http://andreasohlund.blogspot.com Andreas Öhlund

    Hi!

    What’s the current state of the “IsolatedService”?

    I’m getting a strange:

    “Type ‘NServiceBus.Host.Program+<>c__DisplayClass5′ in Assembly ‘NServiceBus.Host, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ is not marked as serializable.”

    I’m setting up my service like this:

    x.ConfigureServiceInIsolation(endpoint.GetType().Name, c =>
    {
    c.WhenStarted(service => service.Start());
    c.WhenStopped(service => service.Stop());
    c.CreateServiceLocator(() => new HostServiceLocator(endpoints));
    });

    Any ideas?

    /Andreas

  • http://andreasohlund.blogspot.com Andreas Öhlund

    Hi!

    What’s the current state of the “IsolatedService”?

    I’m getting a strange:

    “Type ‘NServiceBus.Host.Program+<>c__DisplayClass5′ in Assembly ‘NServiceBus.Host, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ is not marked as serializable.”

    I’m setting up my service like this:

    x.ConfigureServiceInIsolation(endpoint.GetType().Name, c =>
    {
    c.WhenStarted(service => service.Start());
    c.WhenStopped(service => service.Stop());
    c.CreateServiceLocator(() => new HostServiceLocator(endpoints));
    });

    Any ideas?

    /Andreas