Simple Injector

Source
NuGet Package NServiceBus.SimpleInjector (1.x) | License
This is a community maintained project. License and support are independent of Particular Software.
Target NServiceBus Version: 6.x
Standard support for version 6.x of NServiceBus has expired. For more information see our Support Policy.
Starting with NServiceBus version 8, the dependency injection container adapter packages are no longer required. NServiceBus directly supports the Microsoft.Extensions.DependencyInjection.Abstractions model and third party containers can be integrated using the externally managed container mode. Visit the dependency injection upgrade guide for further information.

NServiceBus can be configured to use Simple Injector for dependency injection.

Default usage

endpointConfiguration.UseContainer<SimpleInjectorBuilder>();

Using an existing container

var container = new Container();
container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();

container.Register(
    instanceCreator: () =>
    {
        return new MyService
        {
            Property = "Created outside"
        };
    },
    lifestyle: Lifestyle.Scoped);

endpointConfiguration.UseContainer<SimpleInjectorBuilder>(
    customizations =>
    {
        customizations.UseExistingContainer(container);
    });

DependencyLifecycle Mapping

DependencyLifecycle maps to Simple Injector lifestyles as follows:

DependencyLifecycleSimple Injector lifestyle
InstancePerCallTransient
InstancePerUnitOfWorkScoped
SingleInstanceSingleton

Samples


Last modified