注入原则和自定义服务时出错


Error when injecting doctrine and custom service

我在Symfony3中有一个依赖项注入的问题:

This is my 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; 
}

当运行console命令时,我得到以下错误:

[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

为什么会发生这种情况,我该如何解决?

"arguments"是一个数组,只能出现一次,所以它应该是这样的

some_service:
    class: StagingBundle'Service'SomeService
    arguments: ['@doctrine', '@test.other_service']