Installers

Component: NServiceBus
NuGet Package NServiceBus (4.x)
Standard support for version 4.x of NServiceBus has expired. For more information see our Support Policy.

Installers ensure that endpoint specific artifacts (e.g. queues, directories, databases etc) are installed and configured at endpoint startup install time.

Running installers

By default, installers are only run when the application starts with a debugger attached. This includes applications being debugged remotely.

Installers can be enabled to always run at startup:

var configUnicastBus = configure.UnicastBus();
var startableBus = configUnicastBus.CreateBus();
startableBus.Start(
    startupAction: () =>
    {
        configure.ForInstallationOn<Windows>().Install();
    });

Installers may need to be run depending on the arguments that are provided to the host or aspects the environment the endpoint is hosted in.

For example Installers can be enabled based on the command line arguments provided:

public static void Main(string[] args)
{
    var runInstallers = args.Any(x => x.ToLower() == "/runInstallers");

    var configUnicastBus = configure.UnicastBus();
    var startableBus = configUnicastBus.CreateBus();

    if (runInstallers)
    {
        startableBus.Start(
            startupAction: () =>
            {
                configure.ForInstallationOn<Windows>().Install();
            });
    }
}

or by a machine name convention like:

var configUnicastBus = configure.UnicastBus();
var startableBus = configUnicastBus.CreateBus();

if (!Environment.MachineName.EndsWith("-PROD"))
{
    startableBus.Start(
        startupAction: () =>
        {
            configure.ForInstallationOn<Windows>().Install();
        });
}

Custom installers

To create a custom installer implement the INeedToInstallSomething interface.

public class MyInstaller :
    INeedToInstallSomething
{
    public void Install(string identity)
    {
        // Code to install something
    }
}

Assemblies in the runtime directory are scanned for installers so no code is needed to register them.

Related Articles


Last modified