Project Hosting
NuGet Package NServiceBus.Autofac (3.x)
Target NServiceBus Version: 3.x
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

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

Default Usage


Existing Container Instance

var builder = new ContainerBuilder();
builder.RegisterInstance(new MyService());
var container = builder.Build();
As of Autofac 4.2.1, the ContainerBuilder.Update method is marked as obsolete. In the future, updating the container 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


Last modified