Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Topshelf Update

Greetings Friends,

I wanted to take a moment and let everyone know that a new version of Topshelf is just around the corner. The big feature that I want to take a moment to talk about is something that we have been calling ‘Shelving.’ What this basically allows you to do is xcopy deploy services.

What does this mean?

Well now Topshelf ships with a ‘host’ (Topshelf.Host.exe) that can be used to ‘host’ multiple services. When you install the host (Topshelf.Host.exe /install) or just run it, you should see a ‘Services’ directory appear in the folder it is running in.

Screen shot 2010-06-22 at 7.37.40 PM.png

Inside of this directory you can now place any number of services, each one should be housed in its own folder. The name of the folder is used to drive many specific conventions. If you look inside the default build of Topshelf you will see a folder named ‘clock’.

Screen shot 2010-06-22 at 7.39.32 PM.png

Looking inside the ‘clock’ folder we see:

Screen shot 2010-06-22 at 7.40.01 PM.png

The first thing to notice is the ‘clock.config’ this is the config file for your services app domain. Each folder/service gets its own app domain and in this way we can keep everyone safe and give everyone their own config setup.

Currently the config file tells us which class to call to Bootstrap the service, but we hope to have that happen automatically after we release this all official like.

If you have used Topshelf before then the bootstrapper will look quite familiar:

public class AShelvedClock :


public void InitializeHostedService(IServiceConfigurator<TheClock> cfg)


cfg.HowToBuildService(n => new TheClock());

cfg.WhenStarted(s =>


XmlConfigurator.Configure(new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “clock.log4net.config”)));



cfg.WhenStopped(s => s.Stop());



Which is basically just reusing the existing Topshelf configuration DSL.

UPDATE: My buddy Travis makes a good comment that we need to use ‘AppDomain.CurrentDomain.BaseDirectory’ here to get to our log4net configuration. If you try to use the ‘.’ notation in your path it ends up looking in the bin directory for the ‘topshelf.host.exe’ instead of your service folder. Thanks Travis!

So this is dandy and all, but what really makes this sparkle for me is that, once the host is running it can detect any changes to a given ‘service’ and restart it automatically. Just like IIS.

Topshelf Change Detection.png

I think this is pretty cool. And is going to be the foundation for what I assume will be some sort of MassTransit Service Grid product in the future.

Well, I am not sure there is much more to say other than to ask you to pull it down from github, and tell me what you think! Key things that I still need to finish are removing some duplicate code, and then to ensure there is a clean shut down of services, and hopefully improving the logging.

hit me up on twitter @drusellers with your thoughts.


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.
  • John Simons

    How do I go about disabling a service?
    Do I delete the whole folder or just the config file?

  • http://richarddingwall.name Richard Dingwall

    Would it be possible to automatically add a Windows service when a folder is dropped in the Topshelf Services dir?

    e.g. you might see a service appear for “Clock (Topshelf)”.

    Then remove the service when the clock dir is deleted.

  • Kris

    doh, it’s in the Shelf branch! my bad.

  • Kris

    I pulled latest source from Github, and ran the build.bat (which fails mid-way thru). However, openning up the solution and building seems to work.

    Where is TopShelf.host.exe?

  • Kris

    I pulled latest source from Github, and ran the build.bat (which fails mid-way thru). However, openning up the solution and building seems to work.

    Where is TopShelf.host.exe?

  • http://olsonjeffery.github.com @olsonjeffery

    This is great news. I recently deployed a TopShelf service for a client based on the RC2 release on google code (good to know that development lives on at github).

    I’ll be looking at upgrading the aforementioned service in the near future.

  • http://www.proace.com/author/mweinand/ Mike Weinand

    This is a great new feature! Can’t wait to use it in one of our projects already using Topshelf. We are getting to the point where we have a lot of services running and this will be a much better way to manage all of them.