EDIT: This only works when running the .exe, not when running as a service. As an alternative you could add the option as a configuration value and read it at start-up (which is probably better practice anyway):
using System.Configuration;
// snip
string foobar = null;
HostFactory.Run(configurator =>
{
foobar = ConfigurationManager.AppSettings["foobar"];
// do something with fooBar
configurator.Service<ServiceClass>(settings =>
{
settings.ConstructUsing(s => GetInstance<ServiceClass>());
settings.WhenStarted(s => s.Start());
settings.WhenStopped(s => s.Stop());
});
configurator.RunAsLocalService();
configurator.SetServiceName("ServiceName");
configurator.SetDisplayName("DisplayName");
configurator.SetDescription("Description");
configurator.StartAutomatically();
});
According to the documentation you need to specify the commands in this pattern:
-foobar:Test
You also need to add the definition in your service configuration:
string fooBar = null;
HostFactory.Run(configurator =>
{
configurator.AddCommandLineDefinition("fooBar", f=> { fooBar = f; });
configurator.ApplyCommandLine();
// do something with fooBar
configurator.Service<ServiceClass>(settings =>
{
settings.ConstructUsing(s => GetInstance<ServiceClass>());
settings.WhenStarted(s => s.Start());
settings.WhenStopped(s => s.Stop());
});
configurator.RunAsLocalService();
configurator.SetServiceName("ServiceName");
configurator.SetDisplayName("DisplayName");
configurator.SetDescription("Description");
configurator.StartAutomatically();
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…