Should Laravel support multiple deferred providers for the same service? #39162
Unanswered
mad-briller
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, due to the way Laravel internally processes deferred service providers, only a single service provider may be deferred against a service:
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/ProviderRepository.php#L151
The line linked above assumes that each service will only have one deferred service provider.
However, it is possible to "decorate" services using the
->resolving()
method on the Application, which supports severalresolving
closures for a single service.This means that having multiple service providers which use
resolving()
to decorate a service cannot be deferred:The following code results in only the second deferred provider running when the
Decoratable
service is resolved by the containerIs this intended behavior and a misuse of the service container? or an oversight and opportunity for improvement?
Beta Was this translation helpful? Give feedback.
All reactions