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

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