[英]PHP-DI using annotation injection with factory
我有一個創建對象的工廠。
Abbruchprotokoll::class => factory(function(ContainerInterface $c){
return new Abbruchprotokoll($c->get(Request::class)->getRouterParam('stts-id'), $c->get(MySQL::class));
})
工廠正在使用字符串和依賴項注入(MySQL類)來創建該對象。 在我的Abbruchprotokoll::class
我有一個注入注釋:
/**
* @Inject
* @var \Smarty
*/
protected $smarty;
問題是此注入注釋未解決。 我認為這是因為我在FactoryResolver
並且沒有像ObjectCreator
那樣的injectMethodsAndProperties()
。
我可以通過其他方式在工廠中使用注入注釋嗎?
您不能在工廠中使用批注,而需要使用autowire(Abbruchprotokoll::class)
。 autowire()
要求autowire()
該類,從而解析注釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.