-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Add support for autowiring services as closures using attributes #49628
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
377e267
to
dc3f5e7
Compare
Would this also be supported through yaml auto wiring ? |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
dc3f5e7
to
540b0c8
Compare
#[Autowire]
540b0c8
to
a355993
Compare
Thanks for the feedback. PR (and description) updated with two new attributes: |
… using attributes
a355993
to
9869327
Compare
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 is much more expressive and self-documented.
Merging as this blocks other PRs right now, but feel free to review after merge of course! |
…edLocator]` on controller arguments (HypeMC) This PR was merged into the 6.3 branch. Discussion ---------- [HttpKernel] Add tests for `#[TaggedIterator]` & `#[TaggedLocator]` on controller arguments | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #49083 | License | MIT | Doc PR | - ~~I think this doesn't qualify as a bug fix, but an improvement. If I'm wrong please let me know.~~ #49628 fixed the issue, this PR only adds tests now. Commits ------- 121e072 [DependencyInjection] Add tests for #[TaggedIterator] & #[TaggedLocator] on controller arguments
…avor of `#[AutowireDecorated]` (nicolas-grekas) This PR was merged into the 6.3 branch. Discussion ---------- [DependencyInjection] Deprecate `#[MapDecorated]` in favor of `#[AutowireDecorated]` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - `#[Map*]` are for controller argument resolvers. `#[Autowire*]` should be used for autowiring (see #49628). We could also rename `#[TaggedLocator]` and `#[TaggedIterator]` but I feel like the need is less obvious and the cost more important. Commits ------- b653adf [DependencyInjection] Deprecate `#[MapDecorated]` in favor of `#[AutowireDecorated]`
When dealing with laziness on the consumer side, a common pattern is to wrap a heavy service in a closure and call it only when needed.
This PR adds attribute
#[AutowireServiceClosure]
for this purpose:It also adds support for turning callables into closures with a new
#[AutowireCallable]
attribute:Of course, this fully leverages autowiring aliases, so that instead of "foo", you can use
MyInterface::class
.