Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

GuilhemN
Copy link
Contributor

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21970 (comment)
License MIT
Doc PR

This PR injects defaults and instanceof conditionals in anonymous services to be consistent for all services.

services:
    _defaults:
        autowire: true

    Bar: [ !service { class: Quz } ]

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.

$configuratorService = $this->getChildren($configurator, 'service');

if (isset($configuratorService[0])) {
$class = $this->parseDefinition($configuratorService[0], $file);
Copy link
Contributor Author

@GuilhemN GuilhemN Mar 14, 2017

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.

@nicolas-grekas
Copy link
Member

rebase needed

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Mar 15, 2017
@GuilhemN
Copy link
Contributor Author

@nicolas-grekas done

@GuilhemN GuilhemN force-pushed the ANONYMOUS branch 2 times, most recently from 98ddc3f to ec5b923 Compare March 22, 2017 14:22
@nicolas-grekas
Copy link
Member

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'd be my preference.
If you agree, let's close this PR and work on another one.

@GuilhemN
Copy link
Contributor Author

GuilhemN commented Apr 4, 2017

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.

That'd be my preference.
If you agree, let's close this PR and work on another one.

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).

@GuilhemN GuilhemN closed this Apr 4, 2017
@GuilhemN GuilhemN deleted the ANONYMOUS branch April 4, 2017 17:44
fabpot added a commit that referenced this pull request Apr 5, 2017
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
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request Apr 5, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants