mae*_*tpo 11 service scope symfony
我的目标是将data_collector添加到我的类中,以便在开发人员工具栏上显示一些有用的信息.我的服务:
services:
my_api.auth.login:
class: YO\ApiV1\Services\Auth\Login
arguments:
- requestId
- "@old_sound_rabbit_mq.login_rpc"
- "@service_container"
scope: prototype
Run Code Online (Sandbox Code Playgroud)
我需要范围原型为每个新调用都有不同的实例.顺便说一句,service @ old_sound_rabbit_mq.login_rpc也有范围"prototype".而且,我想附加data_collector,可以通过以下方式完成:
tags:
- { name: data_collector, template: "AcmeDebug:Collector:templatename", id: "your_collector_name" }
Run Code Online (Sandbox Code Playgroud)
但后来我得到了一个例外:
ScopeCrossingInjectionException:检测到Scope Crossing Injection:定义"profiler"引用属于另一个范围层次结构的服务"my_api.auth.login".此服务可能无法始终可用.通常,将定义"profiler"移动到范围"prototype"或将"container"声明为"prototype"的子范围更安全.如果可以确定其他范围始终处于活动状态,则可以将引用设置为strict = false以消除此错误.
它让我感到困惑,因为我不知道该怎么做.我试图设置属性"strict = false",但没有任何反应.
小智 6
我猜symfony的同步服务可以帮助你:doc
否则你可以用这种方式设置"strict = false":
services:
my.service.definition:
class: Acme\Services\BlaService
arguments:
- "@any_other_service_from_narrower_scope="
scope: prototype
Run Code Online (Sandbox Code Playgroud)
从较窄的范围注入服务时,服务定义末尾的"="将"严格"变为false