Over the years, people have often asked me if Rebus had a “generic host”, similar to NServiceBus’ Generic Host. In case you don’t know, NServiceBus’ generic host is a library that helps you easily get an NServiceBus endpoint up and running as a Windows Service.
Rebus doesn’t have a generic host though – and there’s a good reason for that! 🙂
The reason is, that there’s no reason why the Windows Service host should in any way be Rebus-specific!
What you really want in a Windows Service host (and in any host, really) is just a simple model for initializing something, keeping it around for the duration of the program’s lifetime, with proper termination at the end.
The cool thing is that .NET has great built-in mechanisms for initializing and terminating things – they’re called CONSTRUCTORS and
So what if a Windows Service could be composed of something, that should simply be
newed up and disposed afterwards? And what if the hosting library made it possible to also run the app as an Azure Web Job? And what if it could host any number of “things”?
That’s what Topper does! 😎
Topper is built on Topshelf, so that means F5-debugging as a Console Application, and the ability to be installed as a Windows Service.
In addition to this, Topper will detect if it’s running as an Azure Web Job and do what’s necessary to shut down cleanly.
This is what your program can look like with Topper:
static void Main()
var configuration = new ServiceConfiguration()
.Add("first", () => new MyFirstService())
.Add("second", () => new MySecondService());
ServiceConfiguration allows for adding any number of named factories, each returning an
IDisposable, and async factories (
Func<Task<IDisposable>>) are supported, too.
As you can see, there’s no good reason why a “generic host” should be tied to any particular service bus library… so that’s why Rebus does not have a generic host. 🤓