As TosShelf says:
"You can only have ONE service! As of 3.x Topshelf the base product no longer support hosting multiple services.
"
as of version 3.x I need to figure out how to integrate the new version of Topshelf.
Question: Is it possible to start multiple separate services from one Console Application using Topshelf? How can I achieve that?
Topshelf no longer supports this but a possible work around would be to implement a class to start multiple services.
Example:
// ServiceManager is used to start and stop multiple services
hostConfigurator.Service<ServiceManager>(s =>
{
s.ConstructUsingNinject(); // service1 and service2 injected into ServiceManager
s.WhenStarted(tc => tc.Start());
s.WhenStopped(tc => tc.Stop());
});
The ServiceManager class then would just start and stop multiple services.
public class ServiceManager
{
private readonly Service1 service1;
private readonly Service2 service2;
public ServiceManager(Service1 service1, Service2 service2)
{
this.service1= service1;
this.service2= service2;
}
public void Start()
{
service1.Start();
service2.Start();
}
public void Stop()
{
service1.Stop();
service2.Stop();
}
}
As of now there is not a method to host multiple services in a single windows service nor are there plans to implement this functionality. Monitoring and managing these services isn't possible with existing tools which is one of the primary drivers for this decision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With