-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Inject defaults and instanceof conditionals in anonymous services #21999
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
182665a
to
200ae5d
Compare
$configuratorService = $this->getChildren($configurator, 'service'); | ||
|
||
if (isset($configuratorService[0])) { | ||
$class = $this->parseDefinition($configuratorService[0], $file); |
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.
I fixed another bug at the same time, the fact that the factories/configurators were inline meant for prototypes/instanceof conditionals that different instances could be created for one anonymous service which wasn't consistent with how other anonymous services are created.
Note that it wasn't an issue before 3.3 as a service was never cloned.
rebase needed |
@nicolas-grekas done |
98ddc3f
to
ec5b923
Compare
…anonymous services
Thinking again about that, what about going the other way around: have defaults and instanceof apply only to root level definitions, and not to nested (inline) ones? |
That's the current behavior.
I agree, thinking about it again I don't think this change is worth it. Let's close it and open a different PR for #21999 (comment). |
This PR was squashed before being merged into the 3.3-dev branch (closes #22279). Discussion ---------- [DI] Fix anonymous factories/configurators support | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #21999 (comment) | License | MIT | Doc PR | Using prototypes / instanceof conditionals, anonymous factories are inlined using `Definition`, so a new instance will be created for every service created from the prototype / conditional which is inconsistent with the way other anonymous services are managed. Commits ------- dda43ed [DI] Fix anonymous factories/configurators support
This PR was squashed before being merged into the 3.3-dev branch (closes #22279). Discussion ---------- [DI] Fix anonymous factories/configurators support | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | symfony/symfony#21999 (comment) | License | MIT | Doc PR | Using prototypes / instanceof conditionals, anonymous factories are inlined using `Definition`, so a new instance will be created for every service created from the prototype / conditional which is inconsistent with the way other anonymous services are managed. Commits ------- dda43ed8ce [DI] Fix anonymous factories/configurators support
This PR injects defaults and instanceof conditionals in anonymous services to be consistent for all services.
In this example,
Bar
and the anonymous service will be autowired.One special case: instanceof conditionals aren't injected in anonymous services used in instanceof conditionals.