Created
October 5, 2009 01:31
-
-
Save dvhthomas/201740 to your computer and use it in GitHub Desktop.
TopShelf makes service creation a snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using StructureMap; | |
| using Topshelf; | |
| using Topshelf.Configuration; | |
| namespace GisQueryDirectHost | |
| { | |
| internal class Program | |
| { | |
| private static void Main(string[] args) | |
| { | |
| // Set up logging and other application services using StructureMap | |
| ContainerBootstrapper.BootstrapStructureMap(); | |
| try | |
| { | |
| IRunConfiguration cfg = RunnerConfigurator.New(x => | |
| { | |
| x.AfterStoppingTheHost(h => Console.WriteLine("All services are stopping since the host is closing down.")); | |
| x.ConfigureService<QueryHost>("qh", s => | |
| { | |
| // Here comes StructureMap behind the Microsoft ServiceLocator facade | |
| s.CreateServiceLocator(() => | |
| { | |
| ObjectFactory.Initialize(i => | |
| { | |
| i.ForConcreteType<QueryHost>().Configure.WithName("qh"); | |
| i.ForConcreteType<ServiceConsole>(); | |
| }); | |
| return new StructureMapServiceLocator(); | |
| }); | |
| // I have two methods in my QueryHost class...Start and Stop. They simply | |
| // start and stop a WCF service host process | |
| s.WhenStarted(qh => qh.Start()); | |
| s.WhenStopped(qh => qh.Stop()); | |
| }); | |
| x.SetDescription("Supports generation of basic spatial data for clients through an ArcGIS Server query"); | |
| x.SetDisplayName("WCS GIS Query"); | |
| x.SetServiceName("wcsgisquery"); | |
| // You can also specify username/password, or point to app.config in one line of code | |
| x.RunAsLocalSystem(); | |
| }); | |
| Runner.Host(cfg, args); | |
| } | |
| catch (Exception e) | |
| { | |
| Console.WriteLine(e); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment