Symfony 4:服务显示在控制台中,但不显示自动注入
我可以在命令中使用该服务:Symfony 4:服务显示在控制台中,但不显示自动注入,symfony,symfony4,Symfony,Symfony4,我可以在命令中使用该服务: hett@hett-pc:/data/projects/graylist$ ./bin/console debug:container | grep client_manager fos_oauth_server.client_manager alias for "fos_oauth_server.client_manager.default" fos_o
hett@hett-pc:/data/projects/graylist$ ./bin/console debug:container | grep client_manager
fos_oauth_server.client_manager alias for "fos_oauth_server.client_manager.default"
fos_oauth_server.client_manager.default FOS\OAuthServerBundle\Document\ClientManager
但是得到错误
无法自动连线服务“App\Command\TestCommand”:参数
方法“\uu construct()”的“$clientManager”引用了类
“FOS\OAuthServerBundle\Document\ClientManager”,但没有此类服务
存在。无法自动注册,因为它来自di不同的根命名空间 为什么? 以及如何将默认服务与
ClientManagerInterface
关联
PS:我也尝试注入
ClientManagerInterface
,但也出现了同样的错误。Opps,我发现答案比写问题更快:
此服务不支持自动布线,需要将下面的行添加到服务。yaml
:
class TestCommand extends Command
{
protected static $defaultName = 'test';
private $clientManager;
public function __construct(?string $name = null, \FOS\OAuthServerBundle\Document\ClientManager $clientManager)
{
$this->clientManager = $clientManager;
parent::__construct($name);
}
}
services:
FOS\OAuthServerBundle\Model\ClientManagerInterface: '@fos_oauth_server.client_manager.default'