Dependency Injection in PHP 5.3

烂漫一生 提交于 2019-12-21 05:22:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!