2012年6月9日星期六

Luis Atencio's Blog: Dependency Injection in PHP


On his Reflective Thought blog Luis Atencio takes a look at the current state of dependency injection in PHP and shares a simple refactor from non-DI to code that uses it as a service locator.



If you have worked with frameworks such as Spring or Google Guice, you will understand the power and flexibility that dependency injection provides your humongous code base. [...] One quick drawback that I see is that the stateless nature of PHP makes things like object containers not very practical.


He proposes a slightly different kind of dependency injection system, one more akin to what's provided in the Java world where annotation and reflection are components of the integration. He provides a code sample of how this would look and points to Java's JSR-330 standard for some of the annotation examples (like "@inject" or "@scope").

没有评论:

发表评论