我的目标是将data_collector添加到我的类中,以便在开发人员工具栏上显示一些有用的信息。我的服务:
services:
my_api.auth.login:
class: YOApiV1ServicesAuthLogin
arguments:
- requestId
- "@old_sound_rabbit_mq.login_rpc"
- "@service_container"
scope: prototype
我需要范围原型为每个新调用提供不同的实例。顺便说一句,service@old_sound_rabbit_mq.login_rpc也有范围"prototype"。而且,我想附加data_collector,它可以用完成
tags:
- { name: data_collector, template: "AcmeDebug:Collector:templatename", id: "your_collector_name" }
但后来我遇到了一个例外:
ScopeCrossingInjectionException:检测到作用域交叉注入:定义"profiler"引用服务"my_api.auth.login"其属于另一范围层次结构。此服务可能不是持续可用。一般来说,移动将"profiler"定义为作用域"prototype",或将"container"声明为"原型"的子范围。如果你能确定其他范围始终处于活动状态,您可以将引用设置为strict=false以清除的错误。
这让我很困惑,因为我不知道该怎么办。我试图设置属性"strict=false",但什么也没发生。
我想symfony的同步服务可能会对您有所帮助:doc
否则,您可以通过以下方式设置"strict=false":
services:
my.service.definition:
class: AcmeServicesBlaService
arguments:
- "@any_other_service_from_narrower_scope="
scope: prototype
当从较窄的范围注入服务时,服务定义末尾的"="会将"strict"变为false
容器作用域,因为Symfony 2.8已弃用。
scope: prototype
被shared: false
取代
http://symfony.com/doc/2.8/cookbook/service_container/shared.html