How to inject the @request into a service?

后端 未结 9 2258
Happy的楠姐
Happy的楠姐 2020-12-01 05:53

When I try to inject the @request into any of my services, I get this exception:

ScopeWideningInjectionException: Scope Widening Injection detected:

9条回答
  •  孤城傲影
    2020-12-01 06:34

    I think there may have been some misunderstanding about what the official documentation says. In most cases you do want to inject the request directly with a scope="request" attribute on the service element. This makes the Scope Widening go away.

    
    

    or in yml

    zayso_core.openid.rpx: 
        class: Zayso\CoreBundle\Component\OpenidRpx
        public: true
        scope: request
    

    It's only in specific special cases such as Twig extensions where you need to inject the container.

    And kernel is not even mentioned in the page on scopes. Injecting the kernel is far worse (conceptually) than injecting a container.

    UPDATE: For S2.4 and newer, use @Blowski's answer below.

提交回复
热议问题