I have a FormHandler which requires three dependencie-injections: Form, Request and ArticleManager
I configured them this way in services.xml:
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- ArticleManager - Persistence layer -->
<service id="loc_article.manager" class="LOC\ArticleBundle\Entity\ArticleManager">
<argument type="service" id="doctrine.orm.entity_manager" />
<argument>LOC\ArticleBundle\Entity\Article</argument>
</service>
<!-- ArticleForm - Business layer -->
<service id="loc_article.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
</service>
<service id="loc_article.form.type" class="LOC\ArticleBundle\Form\Type\ArticleFormType">
<argument>LOC\ArticleBundle\Entity\Article</argument>
</service>
<service id="loc_article.form.handler" class="LOC\ArticleBundle\Form\Handler\ArticleFormHandler">
<argument type="service" id="loc_article.form" />
<argument type="service" id="request" />
<argument type="service" id="loc_article.manager" />
</service>
</services>
When running app_dev.php, I get following exception:
ScopeWideningInjectionException: Scope Widening Injection detected: The definition “loc_article.form.handler” references the service “request” which belongs to a narrower scope. Generally, it is safer to either move “loc_article.form.handler” to scope “request” or alternatively rely on the provider pattern by injecting the container itself, and requesting the service “request” each time it is needed. In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.
What can I do???
The How to work with Scopes cookbook entry should answer your question.