I'm using ASP.NET Core's builtin DI container. It's missing some features I need, so I need to use a third-party container.
The top ones on Nuget are Autofac and StructureMap. SimpleInjector is consistently the fastest, so I'm considering it too.
I have a large code base, so I want to integrate an external container with minimal disruption and refactoring.
Are any of them drop-in replacements for the builtin container?
I'm not asking a subjective, "which is the best" sort of question. I don't really care. I need to know which is the most compatible.
-
Yeah this is actually quite complicated, there's no real consensus on the matter. But in theory, most containers work as drop-in replacements.grokky– grokky2017年03月10日 16:56:09 +00:00Commented Mar 10, 2017 at 16:56
-
Although almost a decade later :-) ... would you mind mentioning some of such features ASP.NET Core's shipped DI container is/was missing that you had to resort to 3rd party libraries ?Veverke– Veverke2025年03月03日 13:19:24 +00:00Commented Mar 3 at 13:19
2 Answers 2
According to this blog post, all that is required for ASP.NET Core to support your chosen DI container is to implement the IServiceProvider
interface, using a wrapper around your DI container of choice. You're then free to use whatever additional features your container provides.
I've integrated Autofac into my system, and other than the few lines of config, it works as a drop-in replacement.
Other containers probably work too, but I can only confirm for Autofac.
Explore related questions
See similar questions with these tags.