Skip to content

Singly implemented interface service created through factory not having factory method called #34670

Closed
@alecwcp

Description

@alecwcp

Symfony version(s) affected: 4.4 and 5.0

Description
If a service that is an interface created through a factory is only implemented once and its implementation also has no constructor arguments then the factory method doesn't get called when the service is injected.

How to reproduce

  • Minimal code example is available here https://github.com/alecwcp/symfony-di-bug
  • As the README.md says, if you make a second class implenting the interface the problem goes away (even if the second class is unused). The problem also goes away if you add constructor arguments to the implementing class (you then need to exclude that file in the services.yaml - when testing this the arguments weren't autowired for the implementing class).

Additional context

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