News Feed
Sections




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

Padraic Brady's Blog:
Zend Framework 2.0 Dependency Injection (Part 2)
October 13, 2011 @ 09:14:09

Padraic Brady is back today with the second part of his "Dependency Injection in Zend Framework 2.0" series. In this second post he talks about what dependency injection containers are (and aren't) and how they could lead to bad practices if they're considered as service locators.

For Part 2, we're going to dig more into what a DIC is and isn't. I've already noted one very simple DIC called Pimple which will continue as one of my reference points since it best illustrates just how simple a DIC can be. In Part 3, we'll (finally) turn our attention to some actual source code. Baby steps. Parts 1 and 2 should get you thinking so that ZF 2.0′s DIC is a lot easier to understand and critique. We don't want anyone panicking just by throwing them into the deep end.

He talks more about the Pimple DIC tool and how, despite it's similarity to a set of Factory pattern calls, it's slightly different - think of it as "a container of executable Factories". He introduces the concept of a Service Locator, an object that can find and load other objects in an intelligent way. He notes that the most ideal DIC is an "external agent" that defines the object relationships outside of the application.

He points out a feature of ZF2 that allows for injection of the DIC into a controller, allowing it to look up the resources it needs. This of course, has issues - three that he mentions specifically:

  • Firstly, this isn't Dependency Injection.
  • Secondly, it creates objects which are useless without the specific DIC interface it depends on.
  • Thirdly, DICs are really bad Service Locators.
0 comments voice your opinion now!
zendframework dependencyinjection dic pimple servicelocators


blog comments powered by Disqus

Similar Posts

Zend Developer Zone: Zend Framework is a BOSSie Award Winner

Rob Allen's Blog: Zend_Filter_Input / Zend_Validate Messages

Eran Galperin's Blog: On the pitfalls of date validation with the Zend Framework

Rob Allen's Blog: Zend Framework's Flash Messenger action helper

Padraic Brady's Blog: ZF Blog App - Part 4: Design with Blueprint CSS & Zend_Layout


Community Events





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


api series update introduction language laravel library install framework release community symfony zendserver unittest package interview deployment opinion tips podcast

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