Simple Injector

Project Hosting
NuGet NServiceBus.SimpleInjector (2.x) | License
This is a community run project. License and support are independent of Particular Software.
Target NServiceBus Version: 6.x

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

Default Usage

endpointConfiguration.UseContainer<SimpleInjectorBuilder>();

Existing Container Instance

var container = new Container();
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
container.Options.AllowOverridingRegistrations = true;
container.Options.AutoWirePropertiesImplicitly();

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

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

DependencyLifecycle Mapping

The DependencyLifecycle map to Simple Injector in the following way.

DependencyLifecycleSimple Injector Equivalent
InstancePerCallTransient Lifestyle
InstancePerUnitOfWorkPer Execution Context Scope Lifestyle
SingleInstanceSingleton Lifestyle

Samples


Last modified