Federico Cargnelutti

Simple is better than complex. Complex is better than complicated. | @fedecarg

Dependency Injection in Zend Framework

with 4 comments

The Zend Framework is a step closer to having its own DI Container.

Bradley Holt has announced the creation of a new proposal Zend_Container, a simplified version of Zend_Di. According to him, if the framework is going to have a dependency injection component this component needs to be as simple as possible, something along the lines of PicoContainer.

Zend_Container goals:

  • The component’s primary purpose is to replace the use of class-managed singletons and Zend_Registry.
  • The component will only manage singleton items within a container, it will not act as a factory (except for creating the single instance).
  • A container can have zero or one parent container and have access to items in its parent, but a parent cannot have access to items in its children.
  • The component uses reflection to determine dependencies.

The Xyster team has already implemented a similar component, Xyster_Container, a Dependency Injection container based very heavily on PicoContainer, however the main goal of Zend_Container is simplicity.

The good news is that, for the first time, Zend has given the official go-ahead for the development of this component.

More info: Dependency Injection in Zend Framework


Written by Federico

July 29, 2008 at 10:08 am

Posted in Frameworks, PHP

4 Responses

Subscribe to comments with RSS.

  1. Federico – thanks for writing about this! Just for clarification, my proposal is only a draft and has _not_ in any way been approved by Zend.

    Bradley Holt

    July 29, 2008 at 11:46 am

  2. Yes I know, this comment got me excited though:

    Take a look at Ralph’s Zend_Reflection component for any reflection capability you may need. He’s adding something for docblocks specifically.

    Federico

    July 29, 2008 at 10:08 pm

  3. Federico – thanks again for your feedback on my proposal! I’ve made a few updates to the proposal this weekend and added some clarifications about the proposal on my blog:

    Bradley Holt

    August 3, 2008 at 10:18 pm

  4. The fact that Container intends to replace Registry is a good thing, considering that Registry has some design flaws.

    I’ve being looking at ZF’s API and the component names are not very consistent. If your component doesn’t support DI, I would recommend you change the name from Container for Storage (like Symfony), to make it less confusing.

    Thanks for the update

    Federico

    August 4, 2008 at 9:14 am


Leave a Reply