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
jgauffin
source share