From Using the Simple Injector in Simple Injector documentation:
Note: Calling the GetInstance method in the constructor is suboptimal and should be avoided whenever possible. With ASP.NET Web Forms however, it is hard to completely avoid this. Please see the Integration Guide for alternatives.
Why exactly is it suboptimal?
I did notice that this kind of usage can cause issues due to the intentional limitation that the container is locked after the first call to resolve. Thus if you register A, then create a collection of ISomething - one of which has a dependency on A - and then you register that collection using RegisterAll()
, then you run into trouble because one of the ISomethings resolves A, preventing the subsequent registration of the collection.
However I imagine there is more to "suboptimal" than this.