The NServiceBus.Host

Component: NServiceBus Host
NuGet Package NServiceBus.Host (5.x - 6.x)
Target NServiceBus Version: 5.x
Standard support for version 5.x of NServiceBus has expired. For more information see our Support Policy.
The NServiceBus Host is being deprecated as of version 9. Refer to the upgrade guide for further details.

Code walk-through

This sample shows how to host an NServiceBus endpoint using the NServiceBus.Host.

public class EndpointConfig :
    public void Customize(BusConfiguration busConfiguration)

Running code at start and stop time

Since the configuration is done via an implementation of IConfigureThisEndpoint and the host controls the startup process there is no regular way to run code at startup and stop of the endpoint. To enable this scenario, there is an interface that is assembly scanned and executed at these times.

public class MessageSender :
    IBus bus;

    public MessageSender(IBus bus)
        this.bus = bus;

    public void Start()
        var myMessage = new MyMessage();

    public void Stop()

Related Articles

  • Interface lifecycles
    The lifecycles of the various NServiceBus configuration interfaces.
  • NServiceBus Host
    Avoid writing repeat configuration code, host the endpoints in a Windows Service, and change technologies without code.

Last modified