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

Skip to content

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

Closed
@gnutix

Description

@gnutix

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 = ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions