Autofac

Project Hosting
NuGet Package NServiceBus.Autofac (7-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 Autofac for dependency injection.

Default Usage

endpointConfiguration.UseContainer<AutofacBuilder>();

Existing Instance

var builder = new ContainerBuilder();
builder.RegisterInstance(new MyService());
var container = builder.Build();
endpointConfiguration.UseContainer<AutofacBuilder>(
    customizations: customizations =>
    {
        customizations.ExistingLifetimeScope(container);
    });
As of Autofac 4.2.1, the ContainerBuilder.Update method is marked as obsolete. In the future, updating the instance passed to NServiceBus may not be possible.

DependencyLifecycle Mapping

The DependencyLifecycle map to Autofac in the following way.

DependencyLifecycleAutofac Equivalent
InstancePerCallInstance Per Dependency
InstancePerUnitOfWorkInstance Per Lifetime Scope
SingleInstanceSingleInstance

Samples


Last modified