Dependency Injection Container - Factory Sample

I tried to learn about dependency injection and read about them and tried to code a small dependency injection container like this: http://fabien.potencier.org/article/12/do-you-need-a-dependency-injection-container

The only thing that confuses me:

Is the dependency injection container the only glorified implementation of the factory pattern?

If so, why not just call it that why the need for a fancy term only confuses the questions.

If this is not the case, can someone explain that I am not here?

+7
source share
1 answer

You need to separate dependency injection and control inversion.

Dependency injection is that you inject the dependencies into the class, rather than letting the classes themselves be responsible for dependencies.

Inversion Of Control rather means that something takes control of the object and its lifetime. In this case, it is up to the container to decide when and how the object should be created and placed.

Factory pattern - all about creating a new object with every call. The template itself says nothing about how to create dependencies.

This is why you can set different lifetimes and use child containers to manage objects with a limited lifespan.

I wrote an article about it here: http://www.codeproject.com/Articles/386164/Get-injected-into-the-world-of-inverted-dependenci

Or if you like more examples: http://www.codeproject.com/Articles/440665/Having-fun-with-Griffin-Container

+7
source

All Articles