Having a hard time figuring out what makes this code work. If I cut-n-past the example from the 3.0 documentation - it works, however, I get no intellisense on the ServiceConfigurator extension methods. Well, perhaps that's because the parameter on HostFactory.Run is actually a "HostConfigurator" - not a "ServiceConfigurator" for which the "WhenStarted" extension methods are actually defined....
So, Intellisense can't figure this out - how am I supposed to?
WTF (do you think we have enough overloads on this?????)
public static HostConfigurator Service<T>(this HostConfigurator configurator) where T : class, ServiceControl, new();
public static HostConfigurator Service<TService>(this HostConfigurator configurator, Action<Topshelf.ServiceConfigurators.ServiceConfigurator<TService>> callback) where TService : class;
public static HostConfigurator Service<T>(this HostConfigurator configurator, Func<T> serviceFactory) where T : class, ServiceControl;
public static HostConfigurator Service<T>(this HostConfigurator configurator, Func<Topshelf.Runtime.HostSettings, T> serviceFactory) where T : class, ServiceControl;
public static HostConfigurator Service<T>(this HostConfigurator configurator, Func<T> serviceFactory, Action<Topshelf.ServiceConfigurators.ServiceConfigurator> callback) where T : class, ServiceControl;
public static HostConfigurator Service<TService>(this HostConfigurator configurator, Func<Topshelf.Runtime.HostSettings, TService> serviceFactory, Action<Topshelf.ServiceConfigurators.ServiceConfigurator> callback) where TService : class, ServiceControl;
HostFactory.Run(x =>
{
x.Service<TownCrier>(svc => //2
{
// Added 2 lines
Console.WriteLine(s.GetType()); // actually at runtime this is a DelegateServiceConfigurator....
var s = (ServiceConfigurator<TownCrier>) svc; // Explicit cast - now I can see the extension methods...
s.ConstructUsing(name => new TownCrier()); //3
s.WhenStarted(tc => tc.Start()); //4
s.WhenStopped(tc => tc.Stop()); //5
});
x.RunAsLocalSystem(); //6
x.SetDescription("Sample Topshelf Host"); //7
x.SetDisplayName("Stuff"); //8
x.SetServiceName("stuff"); //9
hostConfigurator.SetDescription("FOGIS tävlingsmeddelandemottagare.");
hostConfigurator.SetDisplayName("FOGIS tävlingsmeddelandemottagare");
hostConfigurator.StartAutomatically();
hostConfigurator.RunAsNetworkService();
hostConfigurator.UseLog4Net();
});
}
}
}