Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI][Autowiring] Resolve ambiguous dependency when it is decorated #21351

Copy link
Copy link
Closed
@chalasr

Description

@chalasr
Issue body actions
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Symfony version 3.3

If a service is decorated and the decorator doesn't set the autowiring-type explicitly, then it is judged as ambiguous by the AutowirePass, for example:

class Foo 
{
    public function __construct(AccessDecisionManagerInterface $accessDecisionManager) 
    {
    }
}
AppBundle\Foo:
    autowire: true

Gives:

[Symfony\Component\DependencyInjection\Exception\RuntimeException]
Unable to autowire argument of type "Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface" for the service "AppBundle\Foo".
Multiple services exist for this interface (debug.security.access.decision_manager, debug.se
curity.access.decision_manager.inner).

I think that a nice improvement could be to check that the only 2 alternatives are the decorator and the decorated, and inject the decorator instead of throwing.

I given it a try but calling $this->container->getDefinition('debug.security.access.decision_manager')->getDecoratedService() from the AutowirePass returns null since the DecoratorServicePass calls $decorator->setDecoratedService(null); before that the AutowirePass is called.

Is there something doable in order to make this possible (e.g. changing the AutowirePass priority or avoid calling setDecoratedService(null) on decorators when processing them)?

If nothing can be done, I'll just propose to fix it for this specific service by adding an autowiring-type onto.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.