Dependency Injection: Creating object factories vs. using inversion of control containers

by Arrrr   Last Updated December 16, 2017 21:05 PM

When requiring to use dependency injection, I always use IoC containers such as Ninject, Unity, or the built-in one in ASP.Net Core MVC. However, I've just come across the idea of "why not creating an object factory" and then instead of intercepting calls to parameterized constructors (via IoC containers), retrieve those objects from the factory in a parameterless constructor. For instance:

Dictionary<Type, Func<Object>> TransientFactory;
Dictionary<Type, Object> SingletonFactory; 

In my opinion, this technique would speed up the whole thing, but I'm not sure to what extent that would be true and that is the point of the question. Considering the fact that the life-cycle of the object can be easily controlled in consuming context, what possible advantages can an IoC container provide in this case?



Related Questions



.Net Core C# Replace injected settings

Updated November 08, 2017 20:05 PM