-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
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