public static ServiceConfigurator <T> ConstructUsing <T>(this ServiceConfigurator <T> configurator, Func <T> factory) where T : class { configurator.ConstructUsing((d, name, coordinator) => factory()); return(configurator); }
public static int Main(string[] args) { { var exitCode = HostFactory.Run(c => { c.Service <Service>(service => { c.SetServiceName(ServiceName); c.SetDisplayName(DisplayName); c.SetDescription(ServiceDescription); c.EnablePauseAndContinue(); c.EnableShutdown(); c.StartAutomatically(); c.RunAsLocalSystem(); ServiceConfigurator <Service> s = service; s.ConstructUsing(() => new Service()); s.WhenStarted(a => a.Start()); s.WhenStopped(a => a.Stop()); }); }); return((int)exitCode); } }
private static void Callback(ServiceConfigurator <MyActorService> actorService) { actorService.ConstructUsing(n => new MyActorService()); actorService.WhenStarted(service => service.Start()); actorService.WhenStopped(service => service.Stop()); //continue and restart directives are also available }
static int Main(string[] args) { try { var exitCode = HostFactory.Run(c => { c.Service <DummyRigService>(service => { ServiceConfigurator <DummyRigService> s = service; s.ConstructUsing(() => new DummyRigService()); s.WhenStarted(a => a.Start()); s.WhenStopped(a => a.Stop()); }); c.SetServiceName("DummyRigHamBus"); c.SetDisplayName("DummyRig HamBus server"); c.SetDescription("Web server for DummyRig and hambus"); }); return((int)exitCode); } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); Console.WriteLine("\n\nCould not open COM object! Exiting"); return(-1); } } return(0); }
public static ServiceConfigurator <OrleansService> ConstructUsing(this ServiceConfigurator <OrleansService> self, Action <OrleansServiceConfigurator> configure) { var configurator = new OrleansServiceConfigurator(); configure(configurator); self.ConstructUsing(() => configurator.Build()); return(self); }
public ServiceConfiguratorImpl(ServiceConfigurator <TService> configurator) { _configurator = configurator; _configurator.ConstructUsing((name, coordinator) => FastActivator <TService> .Create()); _configurator.SetServiceName("{0}/{1}".FormatWith(typeof(TService).Name, Guid.NewGuid())); }
public void ConfigureService(ServiceConfigurator <IService> configurator) { configurator.ConstructUsing(BuildService); configurator.WhenStarted((service, control) => service.OnStart(control)); configurator.WhenStopped((service, control) => service.OnStop(control)); }
private static void ConfigureServiceClass(ServiceConfigurator<WindowsService> svc) { svc.ConstructUsing(name => new WindowsService()); svc.WhenStarted(es => es.Start()); svc.WhenStopped(es => es.Stop()); // use this later if/when needed // svc.WhenCustomCommandReceived() }
private static void ConfigureServiceClass(ServiceConfigurator <WindowsService> svc) { svc.ConstructUsing(name => new WindowsService()); svc.WhenStarted(es => es.Start()); svc.WhenStopped(es => es.Stop()); // use this later if/when needed // svc.WhenCustomCommandReceived() }
public static ServiceConfigurator <T> ConstructUsingNinject <T>(this ServiceConfigurator <T> configurator) where T : class { var log = HostLogger.Get(typeof(HostConfiguratorExtensions)); log.Info("[Topshelf.Ninject] Service configured to construct using Ninject."); configurator.ConstructUsing(serviceFactory => NinjectBuilderConfigurator.Kernel.Get <T>()); return(configurator); }
public static ServiceConfigurator <T> ConstructUsingAbp <T>(this ServiceConfigurator <T> configurator) where T : class { var log = HostLogger.Get(typeof(HostConfiguratorExtensions)); log.Info("[Topshelf.Abp] Service configured to construct using Abp."); configurator.ConstructUsing(serviceFactory => IocManager.Instance.Resolve <T>()); return(configurator); }
public static ServiceConfigurator <T> ConstructUsingNinject <T>(this ServiceConfigurator <T> configurator) where T : class { var log = HostLogger.Get("Default"); log.Info("[Topshelf.Ninject] 核心服务已配置为使用Ninject构造 ."); configurator.ConstructUsing(serviceFactory => NinjectBuilderConfigurator.Kernel.Get <T>()); return(configurator); }
public static ServiceConfigurator <T> ConstructUsingStructureMap <T>(this ServiceConfigurator <T> configurator) where T : class { var log = HostLogger.Get(typeof(HostConfiguratorExtensions)); log.Info("[Topshelf.StructureMap] Service configured to construct using StructureMap."); configurator.ConstructUsing(serviceFactory => StructureMapBuilderConfigurator.Container.GetInstance <T>()); return(configurator); }
public static ServiceConfigurator <T> ConstructUsingServiceProvider <T>(this ServiceConfigurator <T> configurator) where T : class { var logger = HostLogger.Get(typeof(HostConfiguratorExtensions)); logger.Info("[Topshelf.MicrosoftDependencyInjection] Service configured to construct using DependencyInjection provider."); configurator.ConstructUsing(serviceFactory => (T)MicrosoftDependencyInjectionBuilderConfigurator.ServiceProvider.GetService(typeof(T))); return(configurator); }
/// <summary> /// Construct a new service for a <see cref="ServiceConfigurator"/> using the pre-configured LightCore <see cref="IContainer"/> /// <seealso cref="HostConfiguratorExtension.UseLightCore(HostConfigurators.HostConfigurator, IContainer)"/> /// </summary> /// <typeparam name="T"></typeparam> /// <param name="configurator"></param> /// <returns></returns> public static ServiceConfigurator <T> ConstructUsingLightCore <T>(this ServiceConfigurator <T> configurator) where T : class { var log = HostLogger.Get(typeof(HostConfiguratorExtensions)); log.Info( string.Format(CultureInfo.InvariantCulture, "[Topshelf.LightCore] Service configured to construct {0} using LightCore.", typeof(T).Name)); configurator.ConstructUsing(serviceFactory => LightCoreBuilderConfigurator.Resolve <T>()); return(configurator); }
public static ServiceConfigurator <T> ConstructUsingStructureMap <T>(this ServiceConfigurator <T> configurator) where T : class { if (typeof(T).GetInterfaces()?.Length > 0 && typeof(ServiceControl).IsAssignableFrom(typeof(T))) { configurator.WhenStarted((service, control) => ((ServiceControl)service).Start(control)); configurator.WhenStopped((service, control) => ((ServiceControl)service).Stop(control)); } configurator.ConstructUsing(GetFactory <T>()); return(configurator); }
private static void UseStartup <TStartup>(ServiceConfigurator <IBusHost> configurator) where TStartup : Startup, new() { var startup = new TStartup(); configurator.ConstructUsing(settings => startup.BuildHost(settings)); configurator.WhenStarted(startup.OnStart); configurator.WhenStopped(startup.OnStop); }
public static ServiceConfigurator <T> ConstructUsing <T>(this ServiceConfigurator <T> configurator, Func <T> factory) where T : class { if (configurator == null) { throw new ArgumentNullException("configurator"); } configurator.ConstructUsing(settings => factory()); return(configurator); }
private void ConfigureService(ServiceConfigurator <AppRootService> serviceOptions) { serviceOptions.ConstructUsing(name => new AppRootService()); serviceOptions.WhenStarted(tc => tc.Start()); serviceOptions.WhenStopped(tc => tc.Stop()); serviceOptions.WhenPaused(tc => tc.Pause()); serviceOptions.WhenContinued(tc => tc.Continue()); serviceOptions.WhenShutdown(tc => tc.Shutdown()); }
public static ServiceConfigurator <T> ConstructUsing <T>([NotNull] this ServiceConfigurator <T> configurator, InternalServiceFactory <T> factory) where T : class { if (configurator == null) { throw new ArgumentNullException("configurator"); } configurator.ConstructUsing((d, name, coordinator) => factory(name, coordinator)); return(configurator); }
static int Main(string[] args) { var exitCode = HostFactory.Run(c => { c.Service <Service>(service => { ServiceConfigurator <Service> s = service; s.ConstructUsing(() => new Service()); s.WhenStarted(a => a.Start()); s.WhenStopped(a => a.Stop()); }); }); return((int)exitCode); }
private static void Setup(ServiceConfigurator <SubscriptionConfigurationService> serviceConfig) { var container = new ContainerBuilder() .RegisterServiceBus() .RegisterObservers(typeof(Program).Assembly) .Build(); var resolver = new Resolver(container.ResolveNamed, container.Resolve); serviceConfig.ConstructUsing( s => new SubscriptionConfigurationService(resolver, map => map.ListenTo <SimpleMessage>().Using <SimpleHandler>().WithConfiguration(new SubscriptionConfiguration("Test_1")) )); serviceConfig.WhenStarted(service => service.Start()); serviceConfig.WhenStopped(service => service.Stop()); }
private static void Setup(ServiceConfigurator<SubscriptionConfigurationService> serviceConfig) { var container = new ContainerBuilder() .RegisterServiceBus() .RegisterObservers(typeof(Program).Assembly) .Build(); var resolver = new Resolver(container.ResolveNamed, container.Resolve); serviceConfig.ConstructUsing( s => new SubscriptionConfigurationService(resolver, map => map.ListenTo<SimpleMessage>().Using<SimpleHandler>().WithConfiguration(new SubscriptionConfiguration("Test_1")) )); serviceConfig.WhenStarted(service => service.Start()); serviceConfig.WhenStopped(service => service.Stop()); }
public static ServiceConfigurator <T> ConstructUsingStructureMap <T>(this ServiceConfigurator <T> configurator) where T : class { var hasInterfaces = typeof(T).GetInterfaces()?.Length > 0; if (hasInterfaces && IsAssignable <ServiceControl, T>()) { configurator.WhenStarted((service, control) => ((ServiceControl)service).Start(control)); configurator.WhenStopped((service, control) => ((ServiceControl)service).Stop(control)); } if (hasInterfaces && IsAssignable <ServiceSessionChange, T>()) { configurator.WhenSessionChanged((service, control, args) => ((ServiceSessionChange)service).SessionChange(control, args)); } configurator.ConstructUsing(GetFactory <T>()); return(configurator); }
static void Main(string[] args) { HostFactory.Run(x => { string instanceName = System.Configuration.ConfigurationManager.AppSettings["WindowsServiceName"]; x.Service <HangFireService>(s => { ServiceConfigurator <HangFireService> s1 = s as ServiceConfigurator <HangFireService>; s1.ConstructUsing(name => new HangFireService()); s1.WhenStarted(tc => tc.Start()); s1.WhenStopped(tc => tc.Stop()); }); //x.RunAsLocalService(); x.RunAsLocalSystem(); x.SetServiceName(instanceName); x.SetDisplayName(instanceName); x.SetDescription(instanceName); }); }
public virtual int Run() { return((int)HostFactory.Run(config => { config.UseLog4Net(); if (_configuration.ServiceName == null) { _configuration.ServiceName = _defaultConfiguration.ServiceName; } if (_configuration.ServiceDisplayName == null) { _configuration.ServiceDisplayName = _defaultConfiguration.ServiceDisplayName; } if (_configuration.ServiceInstanceName == null) { _configuration.ServiceInstanceName = _defaultConfiguration.ServiceInstanceName; } if (_configuration.ServiceDescription == null) { _configuration.ServiceDescription = _defaultConfiguration.ServiceDescription; } config.SetServiceName(_configuration.ServiceName); config.SetDisplayName(_configuration.ServiceDisplayName); config.SetInstanceName(_configuration.ServiceInstanceName); config.SetDescription(_configuration.ServiceDescription); config.Service <HostedService>(service => { ServiceConfigurator <HostedService> hostedService = service; hostedService.ConstructUsing(() => HostedService.Create(_configuration)); hostedService.WhenStarted((s, hostControl) => s.Start(hostControl).Result); hostedService.WhenStopped(s => s.Stopped()); hostedService.WhenPaused(s => s.Paused()); hostedService.WhenContinued(s => s.Continued()); hostedService.WhenShutdown(s => s.Shutdown()); }); })); }
public static ServiceConfigurator <T> ConstructUsingWindsorContainer <T>(this ServiceConfigurator <T> configurator) where T : class { configurator.ConstructUsing(serviceFactory => WindsorHostBuilderConfigurator.WindsorContainer.Resolve <T>()); return(configurator); }
private static void ConfigureService(ServiceConfigurator <ShutdownService> s) { s.ConstructUsing(t => new ShutdownService()); s.WhenStarted(t => t.Start()); s.WhenStopped(async t => await t.Stop()); }
public static ServiceConfigurator <T> ConstructUsingAutofacContainer <T>(this ServiceConfigurator <T> configurator) where T : class { configurator.ConstructUsing(serviceFactory => AutofacHostBuilderConfigurator.LifetimeScope.Resolve <T>()); return(configurator); }
public static ServiceConfigurator <T> ConstructUsingSimpleInjector <T>(this ServiceConfigurator <T> configurator) where T : class { configurator.ConstructUsing(serviceFactory => SimpleInjectorHostBuilderConfigurator.Container.GetInstance <T>()); return(configurator); }
private static void ConfigureService(ServiceConfigurator<BackupService> sc) { sc.ConstructUsing(() => new BackupService()); sc.WhenStarted(s => s.Start()); sc.WhenStopped(s => s.Stop()); }
private static void ConfigureService(ServiceConfigurator <BackupService> sc) { sc.ConstructUsing(() => new BackupService()); sc.WhenStarted(s => s.Start()); sc.WhenStopped(s => s.Stop()); }
/// <summary> /// Constructs the service type using simple injector for dependency resolution. /// </summary> /// <typeparam name="T">Topshelf Service type</typeparam> /// <param name="configurator">The configurator.</param> /// <returns>ServiceConfigurator<T>.</returns> public static ServiceConfigurator <T> ConstructUsingSimpleInjector <T>(this ServiceConfigurator <T> configurator) where T : class { HostLogger.Get(typeof(ServiceConfiguratorExtensions)).Info("[Topshelf.SimpleInjector] Service configured to construct using SimpleInjector."); configurator.ConstructUsing(serviceFactory => SimpleInjectorBuilderConfigurator.ServiceProvider.GetInstance <T>()); return(configurator); }