Unity

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

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

Default Usage

Edit
endpointConfiguration.UseContainer<UnityBuilder>();

Existing Container Instance

Edit
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