simpleinjector / SimpleInjector

An easy, flexible, and fast Dependency Injection library that promotes best practice to steer developers towards the pit of success.
https://simpleinjector.org
MIT License
1.21k stars 155 forks source link

Single constructor requirement incompatible with ASP.NET Core #981

Closed AntMaster7 closed 10 months ago

AntMaster7 commented 10 months ago

I replaced the entire default service provider in my ASP.NET Core application with Simple Injector because I need the dependency on IServiceProvider to resolve to the Simple Injector container. Unfortunately Simple Injector requires implementation types to have only one constructor which is an issue. When Simple Injector tries to resolve IHostLifetime, which is implemented by the internal ConsoleLifetime class from Microsoft, it fails because this implementation type has two constructors. In my opinion Simple Injector should be able to handle this by selecting the constructor with the most satisfiable dependencies. Or is there a way for me to implement this behavior on top of Simple Injector?

AntMaster7 commented 10 months ago

I found an option to solve this issue with container.Options.ConstructorResolutionBehavior.

dotnetjunkie commented 10 months ago

Simple Injector does not follow the MS.DI Conforming Container contract and can't does not allow the built-in container to be replaced with Simple Injector. Integration with ASP.NET Core works differently with Simple Injector. Please follow the official integration guide. This documentation describes how to integrate Simple Injector with ASP.NET Core.