Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] ScopeWideningInjectionException when using synchronized service in YAML #8356

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
gnutix opened this issue Jun 25, 2013 · 2 comments

Comments

@gnutix
Copy link
Contributor

gnutix commented Jun 25, 2013

I'm having a ScopeWideningInjectionException (with the big message about using scope:request or strict=false in rare cases) when injecting a synchronized request into my service in YAML with the following code :

services:
    my_service:
        class: My\Bundle\Service
        arguments: [@whatever]
        calls:
            - [setRequest, ['@?request']]

The same syntax is also used in the framework unit tests :

services:
    depends_on_request:
        class: stdClass
        calls:
            - [setRequest, ['@?request']]

Which is also the same as described in the documentation for YAML : http://symfony.com/doc/current/cookbook/service_container/scopes.html#using-a-synchronized-service

# src/Acme/HelloBundle/Resources/config/services.yml
services:
    greeting_card_manager:
        class: Acme\HelloBundle\Mail\GreetingCardManager
        calls:
            - [setRequest, ['@?request']]

But if I look at the XML example in the documentation, I see something different :

<!-- src/Acme/HelloBundle/Resources/config/services.xml -->
<services>
    <service id="greeting_card_manager"
        class="Acme\HelloBundle\Mail\GreetingCardManager"
    />
    <call method="setRequest">
        <argument type="service" id="request" on-invalid="null" strict="false" />
    </call>
</services>

Here there's a strict="false". So I've tried the following in YAML :

        calls:
            - [setRequest, ['@?request=']]

And now it works fine, no more exception.
But the fact that the unit tests are working and my code does not confuse me. So I'm wondering if there's a bug in the DI component about strict + synchronized in YAML parsing.

What do you think ? Should I also open a PR on the documentation for the missing = ?

@stof
Copy link
Member

stof commented Jun 26, 2013

Closing this as it is a documentation issue (so it is the wrong issue tracker) and there is already a PR fixing it: symfony/symfony-docs#2739

@stof stof closed this as completed Jun 26, 2013
@gnutix
Copy link
Contributor Author

gnutix commented Jun 26, 2013

Thanks for clarifying it out Stof :)

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

No branches or pull requests

2 participants