REQUEST A DEMO

Tag: TopShelf

Configuring Topshelf Using A StructureMap Container

January 20, 2010 At Dovetail we use StructureMap a lot. Lately we’ve also been using Topshelf a lot too. This post takes a look at how you can marry these two technologies together. We will be using the StrucutreMap container to configure which services get started by Topshelf at runtime. Simple Services   Let’s start simple. We need a way to identify which configured types want to get configured to be spun up by Topshelf. To accomplish this I created an interface called ISimpleService which includes only the Start and Stop methods that Topshelf uses to manage the services lifetime.   public interface ISimpleService { void Start(); void Stop(); }   Next up we’ll update and expand the example from my previous post Controlling Application Lifetime In Topshelf to have it implement the ISimpleService. We’ll also add another service in charge of spamming the log file.   public class LogSpamService :…

Controlling Application Lifetime In Topshelf

One of Topshelf’s best features is the ability to easily host one or more services running side by side. In this post we will create a Topshelf service which will shut down the application. Lets take a look at how it is done.     Coordinating the Service   Let’s create a fake Health Monitoring service which will, sometime in the future, tell Topshelf to shut the application down. The Topshelf hook for controlling the state of all the services it is hosting is a type called IServiceCoordinator. Here is the code for our health monitor. public class HealthMonitoringService : IHealthMonitoringService { private readonly IServiceCoordinator _serviceCoordinator; private readonly ILogger _logger; private Timer _timer; private int _healthCheckCount = 0; public HealthMonitoringService(IServiceCoordinator serviceCoordinator, ILogger logger) { _serviceCoordinator = serviceCoordinator; _logger = logger; } public void Start() { _logger.LogWarn("The Health Monitor is starting up");…

Running Multiple Instances of a Windows Service Using TopShelf

September 24, 2009 Here is another one where I post about something Josh and team did that I borrowed and am using to great effect. When a console app or a windows service needed we like to use TopShelf to get the job done. In this post I’ll show how to get two instances of a Windows service running on one machine using TopShelf. Updated: As Mike points out in the comments below as of revision 46 Dru added a command line parameter to handle this scenario. Great! Much better than our hacky solution below (written before this revision). Please skip this post and just add a service install /instance:<name> argument at the command line to install additional windows services. Here is an example: YourApplication.exe service install /instance:NumeroDos Now back to the original post which should be ignored so stop reading now <grin>.…