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

Resolution of IEnumerable<T> for non registered service T. #982

Closed AntMaster7 closed 10 months ago

AntMaster7 commented 10 months ago

I'm not sure if thats actually a bug or not. But to me its a blocking issue. Its about the following error:

SimpleInjector.ActivationException: 'The configuration is invalid. Creating the instance for type IHostLifetime failed. The constructor of type OptionsFactory<ConsoleLifetimeOptions> contains the parameter with name 'postConfigures' and type IEnumerable<IPostConfigureOptions<ConsoleLifetimeOptions>>, but IEnumerable<IPostConfigureOptions<ConsoleLifetimeOptions>> is not registered.

I do believe that if no collection registration has been made for IPostConfigureOptions<ConsoleLifetimeOptions> in this case, Simple Injector should just pass in an empty array of type IPostConfigureOptions<ConsoleLifetimeOptions>(). Does Simple Injector allow me to configure it such that I can implement this behavior myself or is this something thats deeper rooted?

dotnetjunkie commented 10 months ago

Simple Injector forces you to be very explicit and always register the collection, even if it's empty. There are several ways to override this, but I think this comes back to my previous answer: you are trying to replace the built-in container, which is not supported. The problems you are encountering are especially the reason why replacing the built-in container is not supported by Simple Injector. Simple Injector behaves very differently from the MS.DI contract, and it does so very deliberately. For more information, read this.