Unity

Project Hosting
NuGet NServiceBus.Unity (7.x)
Target NServiceBus Version: 6.x

NServiceBus can be configured to use Unity as a dependency injection container.

Default Usage

endpointConfiguration.UseContainer<UnityBuilder>();

Existing Container Instance

var container = new UnityContainer();
container.RegisterInstance(new MyService());
endpointConfiguration.UseContainer<UnityBuilder>(
    customizations: customizations =>
    {
        customizations.UseExistingContainer(container);
    });

DependencyLifecycle Mapping

The DependencyLifecycle map to Unity in the following way.

DependencyLifecycleUnity Equivalent
InstancePerCallTransient Lifetime Manager
InstancePerUnitOfWorkHierarchical Lifetime Manager
SingleInstanceContainer Controlled Lifetime Manager

Last modified