2012年2月29日星期三

Rob Allen's Blog: An introduction to ZendDi


Rob Allen, Zend Framework guru extraordinaire, has posted an introduction to the Dependency Injection container that's a part of Zend Framework 2 - ZendDi.



Zend Framework 2 provides its own dependency injection container, ZendDi which is a key underpinning of the entire framework and especially the MVC system. I have covered before, my thoughts on the reasons for using dependency injection, so this article looks at the fundamentals of using ZendDi.


He includes some sample code showing a current setup involving constructor injection and how it can be refactored to use the new DI container. With the new version, the resource is assigned to the container and that is referenced when a new object type needs to be created. He also briefly touches on setter injections, noting that he prefers them more for optional dependencies and shows how to enable their use in the container as well.

没有评论:

发表评论