The .NET Core DI container is not suitable for developing any application of a reasonable size that uses loose coupling and follows SOLID principles, because:
- This will not help you verify your configuration, which makes it very difficult to diagnose problems that arise due to common incorrect settings. In applications of a reasonable size, it is actually quite difficult to detect these errors yourself.
- You cannot apply cross-cutting issues using interceptors or decorators in a supported manner. This makes maintaining any reasonable size application really expensive.
- Although it supports the mapping of open universal abstractions to open universal implementations, its implementation is rather naive and cannot work with universal types with type restrictions, more complex comparisons of universal types and dispersion.
- It is impossible to make conditional / contextual registration in such a way that when using Auto-Wiring registrations are introduced only to a certain circle of consumers. for example, if you have two components
Service1 and Service2 , which both depend on ILogger , you can inject Service1 with NullLogger and Service2 with FileLogger , or you want Service1 to be introduced with Logger<Service1> and Service2 with Logger<Service2> .
The main reason for the existence of these restrictions is that the purpose of the built-in container is to provide DI capabilities especially to the platform itself while maintaining a minimum set of its functions in the hope that more mature DI containers will be able to integrate with this. In other words, it acts as the smallest common denominator (LCD). Thanks to the LCD function, it can never turn into a full-fledged DI container, which will be practical for application development.
If you are starting with a new and simple project, I advise you to use Pure DI (which means manual components inside the root of the composition without using a container) and enable your types by connecting your own IControllerActivator . Later, when features such as automatic registration and interception will improve the usability of your composition root, switch to one of the installed DI libraries that meets your requirements.
Steven Jun 06 '15 at 11:24 2015-06-06 11:24
source share