News Feed
Sections




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

QaFoo Blog:
ContainerAware Considered Harmful
October 08, 2013 @ 10:10:06

In this new post to the QaFoo blog they talk about a common pattern in framework development - the injection of a dependency injection container - and, more specifically, the ContainerAware interface in the Symfony2 framework and why it's "considered harmful".

The ContainerAware interface (actually ContainerAwareInterface, ContainerAware is a basic implementation of it) is part of the Symfony2 API, but a similar concept is known from many other frameworks and many applications rely on it. It defines only the one method setContainer(), which allows to inject the DIC into into an object so that it can directly retrieve services from it. [...Issues with it include the fact that] accessing the DIC in your classes can seriously harm maintainability and code re-usability in the long run.

They talk about three things specifically that using this sort of development pattern can cause in your application:

  • Reduced testability
  • Hidden dependencies (harder to see when a class has too many)
  • Feature sneak-in (that could promote bad usage practices)
0 comments voice your opinion now!
containeraware harmful dependencyinjection container dependency injection

Link: http://qafoo.com/blog/057_containeraware_considered_harmful.html

blog comments powered by Disqus

Similar Posts

Timothy Boronczyk's Blog: Spaghetti Code Considered Harmful

Fabien Potencier's Blog: Pimple, the small dependency injection container for PHP 5.3

Kevin Schroeder: (Basic) Configuring the Magento 2 Dependency Injection Container

Sam Hennessy's Blog: A Dependency Injection for PHP Manifesto - Part 1 (What I Want)

NetTuts.com: Digging in to Laravel's IoC Container


Community Events





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


library language mvc package series security voicesoftheelephpant update symfony version release interview podcast laravel opinion composer framework community tool introduction

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