Unity

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

NServiceBus can be configured to use Unity for dependency injection.

Default Usage

endpointConfiguration.UseContainer<UnityBuilder>();

Existing 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