News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Ralph Schindler:
DI, DiC, & Service Locator Redux
October 11, 2012 @ 10:43:38

In his latest post Ralph Schindler takes another look at the usefulness of Dependency Injection Containers and whether or not they're the right thing to use for your situation.

To DiC, or not to DiC: that has seemed to be the question in PHP for the last few years. Most people generally agree that injecting dependencies is the right thing to do. For those writing a framework, or any shared codebase where extensibility or the ability to grow the codebase is a core philosophical tenet, not injecting dependencies is doing a disservice to the project in the long run. So, as I've stated before, the question becomes how do we manage the added complexity that comes with practicing dependency injection?

He briefly covers two topics that are often confused - the concepts of a service locator and a true dependency injection container. He then talks about the more correct situations to use each of them, mentioning a few questions you can ask about your app to determine the best fit. To illustrate, he includes a simple example where he mixed the two - DIC for models and service location for the controllers.

0 comments voice your opinion now!
dependencyinjection container servicelocator example dic


blog comments powered by Disqus

Similar Posts

Rob Allen's Blog: Simple Zend_Form File Upload Example Revisited

DZone.com: Closure Object Binding in PHP 5.4

Zend Developer Zone: Lifting the Skirt on Zend Framework 1.5 - Zend_Form

David Otton's Blog: Neat PHP Tricks: How To Assign References to Globals

Zend Developer Zone: Improved Test Assets for Zend_Tool Generated Projects in ZF 1.11.4


Community Events





Don't see your event here?
Let us know!


introduction interview language install unittest laravel refactor framework list threedevsandamaybe api code community release opinion series symfony2 testing developer podcast

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework