Reputation: 10823
I have a base abstract service that depends on the request from the dependency injection container. Here its definition:
services:
acme.controller.abstract.basic:
class: "Acme\CommonBundle\Controller\AbstractBasicController"
abstract: true
calls:
- [setRequest, ["@request"]]
Since this service definition requires the request scope, I change my definition to this:
services:
acme.controller.abstract.basic:
class: "Acme\CommonBundle\Controller\AbstractBasicController"
abstract: true
scope: request
calls:
- [setRequest, ["@request"]]
Now, I inherit this service definition into a concrete service as follow:
services:
acme.controller.website:
class: "Acme\WebsiteBundle\Controller\WebsiteController"
parent: "acme.controller.abstract.basic"
But I get an exception saying that acme.controller.website
has a wider scope than the request object. To fix this, I need to add the scope: request
to my concrete service. But, I would have thought that the scope definition would have been inherited from the base abstract service so it would not be necessary to re-add the scope
parameter to my child service.
Is it the intended behavior to disallow inheritance of the scope
parameter? If yes, maybe you know the reason why it cannot be implemented?
Upvotes: 2
Views: 1931
Reputation: 7279
Yes, it an intended behavior but I don't know the exact reason yet.
// merge in parent definition
// purposely ignored attributes: scope, abstract, tags
$def->setClass($parentDef->getClass());
$def->setArguments($parentDef->getArguments());
$def->setMethodCalls($parentDef->getMethodCalls());
$def->setProperties($parentDef->getProperties());
Src: Source code comment
Upvotes: 1