当我扩展 ContainerAware 或实现 ContainerAwareInterface 时,该服务不会调用 setContainer。
class CustomService implements ContainerAwareInterface
{
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
}
如何在不注入的情况下使用我的服务中的容器?
是否需要将容器对象传递给构造函数或setter?
在 services.yml 文件中进行定义
services:
bundle.service_name:
class: ...
calls:
- [ setContainer, [ @service_container ] ]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)