-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] add factory
argument in the #[Autoconfigure]
attribute and also enabled the use of factory
within instanceof
conditionals
#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
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:
|
dd83b21
to
5b8b26d
Compare
Hi 👋 I hope you're all doing well ❤️ I've updated the PR description and made the necessary code changes. Please let me know if there's anything else you'd like me to adjust 😊 P.S. I haven’t deprecated the constructor argument yet but if you all agree that it should be deprecated, I’m happy to make that change as well. P.P.S. The test failure doesn’t seem related to this PR, it looks like a flaky test. Thanks! 😄 |
PR/commit title does not reflect your code here :) |
@@ -100,6 +100,7 @@ class YamlFileLoader extends FileLoader | |||
'autowire' => 'autowire', | |||
'bind' => 'bind', | |||
'constructor' => 'constructor', | |||
'factory' => 'factory', |
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.
Why does this change the YamlFileLoader when the PR description talks only about attributes ?
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.
the code internally uses the YamlFileLoader to read values found in attributes
this makes me wonder about the yaml + xml + php config formats: they should also support this factory entry
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.
then we should indeed support it in all formats, and make the changelog entry (and the PR title and description) mention that explicitly.
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.
and we should also have tests preventing regressions for those other formats.
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.
Hi @stof @nicolas-grekas 👋 I hope you're both doing well! 😊
I've made the requested changes, please let me know if there's anything else you'd like me to adjust. 😊
Thanks! ❤️
5b8b26d
to
39fae23
Compare
…` attribute and allow instanceof factory
39fae23
to
138b1dd
Compare
#[AsFactory]
attributefactory
argument in the #[Autoconfigure]
attribute and also allow factory
in instanceof
factory
argument in the #[Autoconfigure]
attribute and also allow factory
in instanceoffactory
argument in the #[Autoconfigure]
attribute and also enabled the use of factory
within instanceof
conditionals
This PR adds support for a new
factory
argument in the#[Autoconfigure]
attribute. It also enables the use offactory
ininstanceof
conditionals across all configuration formats.The
factory
argument allows developers to specify how the service should be instantiated, using the same factory syntax already supported in service definitions.✅ Usage Example