You can get service name (and other properties like description and display name) as follows:
HostFactory.Run(x =>
{
x.Service((ServiceConfigurator<MyService> s) =>
{
s.ConstructUsing(settings =>
{
var serviceName = settings.ServiceName;
return new MyService();
});
}
}
Or if your MyService implements ServiceControl
HostFactory.Run(x =>
{
x.Service<MyService>((s) =>
{
var serviceName = s.ServiceName;
return new MyService();
});
}
/***************************/
class MyService : ServiceControl
{
public bool Start(HostControl hostControl) { }
public bool Stop(HostControl hostControl) { }
}
If you need service name inside MyService just pass it as constructor parameter or property.