-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Add Lazy attribute for classes and arguments #52922
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me wonder whether this blurs any lines but I think I'm good with the proposal.
The implementation should be updated to forbid using both Lazy and Autowire since on the attribute is not repeatable.
Going to work on this asap, thanks! |
25cc0f4
to
091395a
Compare
src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes_80.php
Outdated
Show resolved
Hide resolved
091395a
to
461b475
Compare
src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but CS, see also fabbot
src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Fixtures/LazyAutoconfigured.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
Outdated
Show resolved
Hide resolved
69197c0
to
e53db3e
Compare
Thank you @Tiriel. |
This commit adds a Lazy attribute shortcut for service definitions. The goal here is simply to improve the DX with a single attribute for lazy loaded services, while adding the strict minimum amount of new code.
This attribute can be used as a replacement for the
Autowire(lazy: bool|string)
attribute on any autowired argument or for theAutoconfigure(lazy: bool|string)
attribute on an class definition. Both use case support an optional parameter to specify with class/interface should be used for the proxy.Usage on a class:
On a method argument: