NServiceBus currently provides its own IoC container abstraction that supports a variety of containers, such as Autofac, CastleWindsor, Ninject, SimpleInjector, StructureMap, and many more. We’ve been seeing an increasing interest in and usage of Microsoft.Extensions.DependencyInjection, so we did a feasibility study to see if it would be possible to deprecate the NServiceBus conforming container and replace it with the Microsoft.Extensions.DependencyInjection.Abstractions type widely known as
By doing so, NServiceBus would be compatible with all containers that support
IServiceCollection, and there would be no more need for us or the community to write container adapters for NServiceBus. From an educational standpoint, as a team lead or developer, you would no longer need to understand and explain the NServiceBus dependency lifecycle. Once you understand the Microsoft abstraction, the integration with NServiceBus would be seamless. Other scenarios, such as when NServiceBus is hosted inside ASP.NET Core using
IServiceCollection, would also benefit from the easier sharing of common registrations for the container.
There are some drawbacks that come with making this change. We would have to upgrade the minimum required .NET Framework version to 4.6.1, and we could no longer mark the NServiceBus assemblies as CLS compliant, although the code could still be compliant. Another side effect would be that we’d have to deprecate the Spring container adapter since there is no official
The Microsoft Dependency Injection scopes map well to the NServiceBus container abstraction. Users transitioning to using the Microsoft scopes will be guided through deprecation messages in code as well as extensive upgrade guides on our documentation site.
- What do you think about the plan of replacing the NServiceBus container abstraction with
- Do you see benefits to moving to
IServiceCollectionin your projects?
- Do you see your projects switching to
IServiceCollectionin favor of the DI container you are currently using?
Your input is much appreciated.