8000 autowire on servicecontainer · Issue #18132 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

autowire on servicecontainer #18132

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
FloSeas opened this issue Mar 12, 2016 · 6 comments
Closed

autowire on servicecontainer #18132

FloSeas opened this issue Mar 12, 2016 · 6 comments

Comments

@FloSeas
Copy link
FloSeas commented Mar 12, 2016

I found a strand behavior with servicecontainer and autowire.

When I inject a service container and autowire it, the parameter bag is not resolved.

Basicly, with this definition of my service

    widget.manager:
        class: Widgets\Bundle\CoreBundle\Manager\WidgetManager
        arguments: ['@widget.renderer', '@service_container']

I am able to get parameters like:

$this->serviceContainer->getParameter('my.param')

But when I use autowire like this

    widget.manager:
        class: Widgets\Bundle\CoreBundle\Manager\WidgetManager
        autowire: true

on the same service, the parameter bag is not resolved and i get an error like "the prameter 'my parameter' does not exist".

Maybe it's a normal behavior, cause the service container is a special service, but we should have at least some meaningfull error.

@weaverryan
Copy link
Member

This should already be fixed by #17261, which is released on 2.8.2 and 3.0.2. @poneymagique what version of Symfony are you using?

@FloSeas
Copy link
Author
FloSeas commented Mar 12, 2016

it was 3.0.3

8000

@weaverryan
Copy link
Member

Ah, then did you type-hint with Container $container? The fix is only for type-hinting with ContainerInterface

@weaverryan
Copy link
Member

See #18137 for the fix

@weaverryan
Copy link
Member

Status: Reviewed

fabpot added a commit that referenced this issue Mar 12, 2016
…or of other services (weaverryan)

This PR was merged into the 2.8 branch.

Discussion
----------

Autowiring the concrete class too - consistent with behavior of other services

| Q             | A
| ------------- | ---
| Branch        | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18132
| License       | MIT
| Doc PR        | n/a

This follows #17261. Without this, if you use the concrete class `Container`, it doesn't autowire, so it creates a *new* one. That is certainly not what the end-user wants, and it's a serious WTF :). We can talk all day long about not injecting the container and type-hinting interfaces, but this is needed to be consistent with how all the other services in the container work and to avoid this odd behavior.

Thanks!

Commits
-------

2ea3f68 Autowiring the concrete class too - consistent with behavior of other services
@fabpot fabpot closed this as completed Mar 12, 2016
@FloSeas
Copy link
Author
FloSeas commented Mar 12, 2016

The code is at work, but i guess i type hinted with Container, so your Pr will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0