Can I run multiple services from the same Topshelf console application?

As TosShelf says:

"You can only have ONE service! As of 3.x Topshelf the base product no longer support hosting multiple services. "

from version 3.x I need to figure out how to integrate the new version of Topshelf.

Question: Is it possible to run several separate services from one console application using Topshelf? How can i achieve this?

+5
source share
2 answers

Topshelf no longer supports this, but the possible work is to implement a class to run 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 starts and stops several 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();
    }
}
+9
source

Windows, . , .

+1

All Articles