News Feed
Jobs Feed
Sections




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

Reddit.com:
Dependency injection in ZF2 and Symfony 2 are service locators
April 16, 2013 @ 12:40:07

On Reddit's PHP section there's a discussion happening about dependency injection versus service locators in two popular PHP frameworks - Zend Framework 2 and Symfony 2 (and how they're not really DI at all).

Both ZF2 and Symfony 2 offer the same behavior: if I'm in a controller, and I want to use a service, I have to get it from the container with $this->get('my_service'). As such, the controller is not using DI, this is the service locator pattern. Controllers become more difficult to tests because of that, and they depend on the container now. I wonder why both frameworks didn't go further: why not treat controllers like services and use dependency injection on them. In other words: if a controller needs a service "A", then it should get it in the constructor, or through setter/property injection.

The comments talk some about the "controller from the DI container" idea, some other ways around the problem and some clarification as to what the frameworks are actually doing related to the container injection.

0 comments voice your opinion now!
dependency injection service locator controller framework zendframework2 symfony2

Link: http://www.reddit.com/r/PHP/comments/1caidn/dependency_injection_in_zf2_and_symfony_2_are

blog comments powered by Disqus

Similar Posts

Oracle Technology Network: Building PHP Applications Using the ATK Framework

Stefan Koopmanschap's Blog: symfonyUnderControl: lime integration with phpUnderControl

Sam Hennessy's Blog: A Dependency Injection for PHP Manifesto - Part 0 (Preface)

Felix Geisendorfer's Blog: How to oraganize your CakePHP App's Javascript II

Felix Geisendofer's Blog: Screencast #1: Using vendor branching and CakePHP


Community Events











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


application example install symfony2 hhvm component unittest project framework introduction composer package performance language database podcast release facebook hack security

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