Symfony 2 Dependency Injection & autowiring

I am browsing Symfony 2 documents related to Injection of Dependency and cannot find a link to autogrow. I found a package that offers some of these features , but it is still in beta and seems to be tied to the annotation (correct me if I am wrong).

What I'm looking for is an object (like a service container) that can embed dependencies in my services using the setter installation.

For example, I would define a Service:

class Service {
    /**
     * @var \PDO
     */
    protected $pdo;

    /**
     * @param \PDO $pdo
     * @Inject
     */
    public function setPDO(\PDO $pdo) {
        $this->pdo = $pdo;
    }
}

And then, I could use this hypothetical service container for dependency injection in the Service, even if this one was created outside the container:

$service = new Service();
// ...

$container->inject($service);

Is there a DI container that could auto-attach dependencies this way?

+5

All Articles