问题
I am trying to tidy up an application, and have manually been doing Constructor Dependency Injection for a while.
This is a bit tedious, and I would like to start utilizing a Dependency Injection Container instead.
I am looking for an actively developed and maintained DI container. I have found Crafty as an alternative, which can wire together dependencies with XML, YAML, Arrays or programatically.
The DI container should not be tightly coupled with a full blown framework, we are looking for something simple and pluggable, with the least hassle possible.
Does anyone have a recommendation and why you chose the particular implementation? Thanks for reading.
回答1:
Since people seem to like my comment, I post it as an answer. I do not have experience of it, but i know of Symfony Dependency Injection library. It should be decoupled from the rest of the framework and it seems to be pretty flexible. Check it out at Symfony Components.
I also think Substrate looks pretty good. According to the author, it also has production experience, which is always good.
回答2:
Bucket seems to fit well with your requirements.
回答3:
You can also check out PHP-DI, it features dependency injection through annotations (@Inject
) and minimal configuration.
It's very easy to use, and it integrates with Zend Framework very well (if ever you are using it).
(disclaimer: I do work on this framework)
来源:https://stackoverflow.com/questions/4488269/dependency-injection-in-php-5-3