-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] add #[AsFactory]
attribute
#60589
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
base: 7.4
Are you sure you want to change the base?
Conversation
e3fc70f
to
e09532c
Compare
e09532c
to
52cdb9a
Compare
I like the feature and I know the But thinking about it a bit more: I believe it would be a better option to reuse the existing |
Hi @zolex, thanks for your comment ❤️ I really appreciate it 😄 |
I was thinking a bit about this, and I have a question 🤔 I’m asking this from a place of curiosity and ignorance, totally open to discussion if I’m missing something 🙂 |
I would definitely prefer the argument to be called factory. If you introduce a factory argument, maybe also support a string for a method in the same class like constructor does and at the same time deprecate the constructor argument to prepare the people to migrate to the factory argument. It was a bad naming anyway. |
I like that idea 😄 If others agree, I can go ahead and make that change:
|
✅ Add
#[AsFactory]
Attribute for Declaring Factory ServicesThis PR introduces a new attribute:
#[AsFactory]
, which allows developers to declare a service factory directly on a class using attributes, instead of via configuration files.✅ Usage Example
Instead of configuring a factory in
services.yaml
:You can now use the attribute directly: