我在Symfony3中遇到依赖注入问题:
这是我的services.yml
some_service:
class: StagingBundle\Service\SomeService
arguments: ['@doctrine']
arguments: ['@test.other_service']
这是SomeService.php
的构造函数public function __construct($doctrine, SomeService $someService)
{
$this->doctrine=$doctrine;
$this->someService=$someService;
}
运行我的控制台命令时出现以下错误:
[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 2 passed to stagingBundle\Service\SomeService::__construct() must be an instance of StagingBundle\Service\OtherService, none given, called in /var/www/projects/myApp/var/cache/dev/appDevDebugProjectContainer.php on line 1141 and defined
为什么会发生这种情况,我该如何解决?
答案 0 :(得分:2)
"参数"是一个数组,只能在那里一次,所以看起来应该是这样的
some_service:
class: StagingBundle\Service\SomeService
arguments: ['@doctrine', '@test.other_service']