So this is my quasi-new project. It is essentially the MassTransit.Host ripped out and in its own project. It is also the embodiment of my lessons learned about building services (daemons) on the windows platform.
Sample Code
var cfg = RunnerConfigurator.New(x =>
{
x.SetDisplayName("Timeout Service");
x.SetServiceName("mt_timeout");
x.SetDescription("Runs the MassTransit Timeout Service");
x.ConfigureService<TestService>(c=>
{
c.WithName("my_service"); //this defaults to type name
c.WhenStarted(s => s.Start());
c.WhenStopped(s => s.Stop());
c.WhenPaused(s => { });
c.WhenContinued(s => { });
});
x.ConfigureService<TestService>(); //defaults (still working on this)
//By default the service is set to start automatically
x.DoNotStartAutomatically();
//several different runas options
x.RunAs("dru", "pass");
x.RunAsLocalSystem();
//x.RunAs(AppConfig("username"), AppConfig("password"));
x.RunAsFromInteractive();
//set service dependencies
x.DependsOn("ServiceName");
x.DependencyOnMsmq();
x.DependencyOnMsSql();
});
Runner.Host(cfg, args)
This code would be in a .Net console application and would be executed like:
timeoutservice.exe #Runs as a console
timeoutservice.exe /install #installs the service
timeoutservice.exe /uninstall #uninstalls the service
timeoutservice.exe /gui #runs the default winform (must be in container)
So, here are some of the things it provides: start/stop individually hosted services; run the service in console, service, or winform hosts; self service installing; delayed container setup for faster install/uninstall; POCO and some things it will provide soon: services start/stop won't effect other services, WMI integration.
I don't see this as a game changing project, more than it is a place to harvest my education, and share with others. So if you write winservice code take a look and see if there is anything you can pass along yourself, if you don't write winservice code but need to this can go a long way to helping that out.
Topshelf requires you to use an IoC container, which has made writing this project so much easier as I can focus on the service aspects and less on the object creation. I am using the Common Service Locator so you can use whatever container you want. I am also directly using the log4net framework at the moment and that is about all that their is for dependencies.
The big win for me is that I can now start my app as a console, test it, and then when happy run it as a service knowing its running in exactly the same way.
The project also provides hooks into some of the more esoteric error events so that we can log the more odd errors.
Its hosted at http://topshelf.googlecode.com/
I also want to take a minute to throw out some props to Chris Patterson my partner in crime and Jeremy Miller for the mad FI skills I keep ripping off from StructureMap.
-d
Posted
Sun, Jan 11 2009 5:27 PM
by
drusellers