Installers

Component: NServiceBus | Nuget: NServiceBus (Version: 6.x)

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

To create a custom installer implement the INeedToInstallSomething interface.

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

        return Task.CompletedTask;
    }
}

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

Installers can be enabled to run at startup:

Edit
endpointConfiguration.EnableInstallers();

// this will run the installers
await Endpoint.Start(endpointConfiguration)
    .ConfigureAwait(false);

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:

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

    if (runInstallers)
    {
        endpointConfiguration.EnableInstallers();
    }
}

or by a machine name convention like:

Edit
if (!Environment.MachineName.EndsWith("-PROD"))
{
    endpointConfiguration.EnableInstallers();
}
Installers are always run when the application is run with a debugger attached. This includes when the application is being debugged remotely.

Last modified