Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[DependencyInjection] added AutoDecorationServicePass#38432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
c76bab0
to4787f9d
Compare…or DecoratorPriorityAwareInterface
That's a major issue IMHO. I think we should not do this. We added a new syntax to stack decorators in 5.1, did you try it? See#36373 |
Hi@nicolas-grekas , thanks for the feedback ;) I guess we agree on this point :p I did not use the The thing is that you will always be required to add new elements to the stack, right ? Could there be an option to bind this stack to an interface (which would come from the app, and not the DI component then, to avoid coupling, but in that case, I don't see many options to handle the priority) ? |
I think that decorators are best configured via explicit configuration. I don't see how an interface can help auto-stack them without leaking DI configuration details (service ids) into actual code. This looks like a dead-end to me sorry. |
I did spend some time turning this around and I eventually came to the same conclusion, nothing to be sorry about@nicolas-grekas , itdoes look like a wrong design, thanks again for the feedbacks ;) Alternative thoughts : I was wondering if there could be a way to allow Still, the journey inside the contribution process and the components was quite interesting and gave me more confidence, can't wait for future opportunities to try to fix a bug or else ;) I'll close this one ! |
Uh oh!
There was an error while loading.Please reload this page.
Hi everyone,
Here is a feature proposal for symfony/dependency-injection : implement a configuration-less decoration feature (auto decoration ?).
Every service definition whose class implements
DecoratorInterface
will be automatically marked as a decorator for the service returned byDecoratorInterface::getDecoratedServiceId()
In addition to
DecoratorInterface
, a second interfaceDecorationPriorityAwareInterface
is provided to provide the decoration priority.To explain the "why" part, I encountered a few times already the use-case where it is required to maximize the use of decoration, leading to multiple decorators cascading, and therefore, to multiple lines in
services.yaml
. This will allow developers to use "abstract decorators" or traits to share the decoration behaviour upon multiple classes.The advantage is that it would no longer be required to write decorator definition in configuration files for the majority of decoration use cases.
The limitations of this approach are the same as the one using autowiring, plus, It would add code coupling between service classes and the DI component, which is why this should be considered as an optional feature.
Here is an example
Before
After
or
Looking forward for your remarks/reviews, especially as it is my first time here, I might have done something wrong 🐶