Unity

Project Hosting
NuGet Package NServiceBus.Unity (8-pre)
Target NServiceBus Version: 7.x
This page targets a pre-release version and is subject to change prior to the final release.

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

Samples


Last modified