Created
August 27, 2010 16:09
-
-
Save KevM/553652 to your computer and use it in GitHub Desktop.
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
| [TestFixture] | |
| public class topshelf_configuration_extension | |
| { | |
| [Test] | |
| public void required_simple_services_should_be_registed_with_topshelf() | |
| { | |
| var container = new Container(c=>c.For<IRequiredService>().Use<TestRequiredService>()); | |
| var logger = MockRepository.GenerateMock<ILogger>(); | |
| var runConfiguration = RunnerConfigurator.New(config => config.ConfigureRequiredServices(container, logger)); | |
| runConfiguration.Coordinator.GetServiceInfo().First().Name.ShouldStartWith(typeof(TestRequiredService).Name); | |
| } | |
| } | |
| public class TestRequiredService : IRequiredService | |
| { | |
| public void Start() | |
| { | |
| throw new NotImplementedException(); | |
| } | |
| public void Stop() | |
| { | |
| throw new NotImplementedException(); | |
| } | |
| } | |
| public static void ConfigureRequiredServices(this IRunnerConfigurator configurator, IContainer container, ILogger logger) | |
| { | |
| var simpleServiceInstances = container.Model.InstancesOf<IRequiredService>(); | |
| foreach (var simpleServiceInstance in simpleServiceInstances) | |
| { | |
| var requiredServiceType = simpleServiceInstance.ConcreteType; | |
| logger.LogDebug("Configuring Topshelf to manage the lifecycle of a required service. Service type: {0}", requiredServiceType); | |
| configurator.ConfigureService<IRequiredService>(service => | |
| { | |
| service.Named("{0}:{1}".ToFormat(requiredServiceType.Name, Guid.NewGuid())); | |
| service.HowToBuildService( name => container.GetInstance(requiredServiceType)); | |
| service.WhenStarted(s => s.Start()); | |
| service.WhenStopped(s => s.Stop()); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment