Container changes in Version 6

Component: NServiceBus

Configure type removed

In Version 5 the Configure type was used to provide runtime access to the local endpoint address, scanned types etc via dependency injection. In Version 6 these values can now be accessed as follows:


Settings can be accessed via the FeatureConfigurationContext, see features for more details. Runtime access via the container is provided by taking a dependency on the ReadOnlySettings type.


This is no longer supported. It is advised to, instead of using IBuilder directly, use dependency injection via the container of choice.

Scanned types

Access to types found during assembly scanning is provided via Settings.GetAvailableTypes().

Local address

Access to the endpoint address is provided via Settings.LocalAddress().

Encryption Service

It is no longer possible to access the builder to create an encryption service. If container access is required use the container directly in the factory delegate in the RegisterEncryptionService method.


Conventions are no longer be injected into the Container. Conventions need to be retrieved with Settings.Get<Conventions>() over ReadOnlySettings.

Dependency injection

Explicitly setting property values via .ConfigureProperty<T>() and .InitializeHandlerProperty<T>() has been deprecated. Instead configure the properties explicitly using:

6.x NServiceBus
    registration: components =>
            componentFactory: builder =>
                return new MyHandler
                    MyIntProperty = 25,
                    MyStringProperty = "Some string"
            dependencyLifecycle: DependencyLifecycle.InstancePerUnitOfWork);

IConfigureComponents no longer registered in the container

To access it at runtime create a new Feature and put the following code in the .Setup method

6.x NServiceBus
var container = context.Container;
    componentFactory: builder => new MyDependency(container),
    dependencyLifecycle: DependencyLifecycle.InstancePerCall);

Containers passed to the configuration API are no longer disposed

6.x NServiceBus.Autofac
var builder = new ContainerBuilder();
builder.RegisterInstance(new MyService());
var container = builder.Build();
    customizations: customizations =>

While the above example shows how an existing container can be passed into the configuration API using Autofac, the same behavior can also be applied to all of the currently supported container adapters. Previous versions of the containers treated the externally passed in container as if it was owned by the container adapter and disposed the container when the bus was disposed. This behavior changed. When a container customization is passed like above, then the container is no longer disposed. It is the responsibility of the container owner to dispose the container.

6.x NServiceBus.Autofac

The above example shows how a new container can be assigned using the Configuration API. While the container used in this example is Autofac, the same behavior can also be applied to all of the currently supported container adapters. When passing a new container, the endpoint owns the container and will also be responsible for disposing the container when it is stopped.

Related Articles

  • Containers
    NServiceBus automatically registers components, handlers, and sagas.

Last modified