# NServiceBus.SimpleInjector

**NOTE:** 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](https://docs.particular.net/nservicebus/dependency-injection/#externally-managed-mode). Visit the [dependency injection upgrade guide](https://docs.particular.net/nservicebus/upgrades/7to8/dependency-injection) for further information.

NServiceBus can be configured to use [Simple Injector](https://simpleinjector.org) for dependency injection.


### Default usage

```
endpointConfiguration.UseContainer<SimpleInjectorBuilder>();
```


### Using an existing container

```
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

[`DependencyLifecycle`](/nservicebus/dependency-injection/) maps to [Simple Injector lifestyles](https://simpleinjector.readthedocs.io/en/latest/lifetimes.html) as follows:

| `DependencyLifecycle`                                                                                             | Simple Injector lifestyle                                                                                                        |
|-----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| [InstancePerCall](/nservicebus/dependency-injection/)                                | [Transient](https://simpleinjector.readthedocs.io/en/latest/lifetimes.html#transient)         |
| [InstancePerUnitOfWork](/nservicebus/dependency-injection/)                    | [Scoped](https://simpleinjector.readthedocs.io/en/latest/lifetimes.html#perexecutioncontextscope) |
| [SingleInstance](/nservicebus/dependency-injection/)                                  | [Singleton](https://simpleinjector.readthedocs.io/en/latest/lifetimes.html#singleton)                          |

Migrate docs from Particular site
Migrate docs from Particular site