ScopeCrossingInjectionException ・・・
のエラーが出た時のメモ
use JMS\DiExtraBundle\Annotation as DI;
アノテーションを利用していて以下のようにInjectをした時にエラーが出た。
/**
* Constructor.
*
* @DI\InjectParams({
* "validatorHelper" = @DI\Inject("xxx_util.validator_helper"),
* })
* @param ValidatorHelperInterface $validatorHelper
*/
public function __construct(
ValidatorHelperInterface $validatorHelper
) {
$this->injectedValidatorHelper = $validatorHelper;
}
ScopeCrossingInjectionException: Scope Crossing Injection detected: The definition “************” references the service “xxx_util.validator_helper” which belongs to another scope hierarchy.
This service might not be available consistently.
Generally, it is safer to either move the definition “************” to scope “prototype”, or declare “container” as a child scope of “prototype”.
If you can be sure that the other scope is always active,
you can set the reference to strict=false to get rid of this error.
エラー文の最後に書いてあるように「strict=false」を追加すれば通った。
/**
* Constructor.
*
* @DI\InjectParams({
* "validatorHelper" = @DI\Inject("xxx_util.validator_helper", strict = false),
* })
* @param ValidatorHelperInterface $validatorHelper
*/
public function __construct(
ValidatorHelperInterface $validatorHelper
) {
$this->injectedValidatorHelper = $validatorHelper;
}
エラーをちゃんと最後まで読もう・・・。
■参考URL
Bundles/JMSDiExtraBundle/Annotations
http://jmsyst.com/bundles/JMSDiExtraBundle/master/annotations#inject