So i came across this post http://blog.akinyeleolubodun.com/the-simplest-explanation-of-dependency-injection-di.html which was supposed to be explanation on Dependency Injection (DI). In my opinion i felt his tutorial was wrong and didn’t explain DI as it is. So i want the opinion of other as regards the post. My comment as regards the post is as below.
Dude, no offence but that’s not a solid conclusion to DI. Secondly i googled the Fabien Potencier and i think the way he concluded his article is quite different from yours and you may have missed the whole point of DI or you just didn’t explain it well. allow me to quote you “inject the SessionStorage object in the User object”
You didn’t bother explaining who does the Injection or how the creation of the object and passing of the argument to the constructor is done achieved (which is done by containers anyway). An additional framework is required to achieve DI (Whether you create it yourself or not). DI is not just done by writing up some php script for you pending project and structuring it in an OOP way. Furthermore, the framework that provides the container for injection of objects has to be totally independent of the code your’re putting together such that the framework can be reused over and over in multiple projects. If i didn’t have a firm grip of dependency injection myself i’d assume that what you where explaining up there was just Plain Old Creating an Object by passing a reference to it’s constructor.
All said and done, my brother this code as lifted from above
$storage = new SessionStorage(‘SESSION_ID’);
$user = new User($storage); // In DI you not get to create User yourself some form of container creates it for you.
IS DEFINITELY NOT DEPENDENCY INJECTION