我正在將Symfony DIC集成到zend框架應用程序中,除了父服務之外,這很好。Symfony DIC和父服務不起作用
在我的DIC配置中,我有一個父服務PC_Service,它將被我的所有服務擴展。 問題是實體管理器在擴展PC_Service的服務中不可用(NULL)。當我通過service.stats注入entitymanager時,entitymanger設置正確。
...
<service id="pc.service" class="PC_Service" abstract="true">
<call method="setEntityManager">
<argument type="service" id="doctrine.entitymanager" />
</call>
</service>
...
<service id="service.stats" class="Application_Service_Stats" parent="pc.service" />
...
PC_Service
abstract class PC_Service
{
protected $_em;
public function setEntityManager($entityManager)
{
$this->_em = $entityManager;
}
}
Application_Service_Stats
class Application_Service_Stats extends PC_Service
{
... $this->_em should be set here.
}
我希望有人能告訴我什麼,我做錯了。
有沒有比使用symfony2更簡單的將學說融入zend的方法? – Ascherer 2012-03-12 06:11:57
這不是關於整合原則,而是關於依賴注入 – tom 2012-03-12 06:14:06
你最終找到解決方案嗎?我遇到了同樣的問題,並且正在通過Symfony代碼進行分析(不幸的是,至今沒有多少運氣) – 2012-05-19 17:34:55