Skip to content

Inconsistent Non-Shared Services #37863

@natewiebe13

Description

@natewiebe13

Symfony version(s) affected: 4.x, 5.x (potentially more)

Description
When configuring a service with shared: false, autowiring multiple instances within a controller action will return new instances, but autowiring into a service (including controllers) via __construct() will return the same instance.

I think it would be best for either situation to behave similarly or if this behaviour is intended, it should be documented. Probably here: https://symfony.com/doc/current/service_container/shared.html

How to reproduce
A reproducer has been created here: https://github.com/natewiebe13/symfony-service-inconsistency/pull/1 oddly enough, if we also try to autowire the non-shared service through the constructor, a ServiceNotFoundException is thrown which is likely a separate issue from this one. A reproducer for the exception is here: https://github.com/natewiebe13/symfony-service-inconsistency/pull/2

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