[DependencyInjection] added AutoDecorationServicePass #38432
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 🐶