Symfony4.2 Autowire捆绑服务

时间:2019-04-23 08:54:49

标签: symfony4 symfony-4.2

我想在自己的服务中自动捆绑服务接口,但出现错误:

neg_feats

我的代码是:

Cannot resolve argument $slackOauthService of "App\Controller\Panel\Slack\SigninController::afterOauth()": Cannot autowire service "App\Service\Slack\SlackOauthService": argument "$httpClient" of method "__construct()" references interface "GuzzleHttp\ClientInterface" but no such service exists. Did you create a class that implements this interface?

如果仅注入实体管理器或由我定义的服务,则一切正常,但是无论我尝试注入的捆绑服务(枪口,浏览器套件,jms序列化器等)都无法正常工作。

我具有为Web项目定义的默认symfony services.yaml文件:

public function __construct( ClientInterface $httpClient, EntityManagerInterface $em ) {
        $this->httpClient = $httpClient;
        $this->em         = $em;
    }

我正在使用Symfony4.2。

该问题的解决方案是什么?

1 个答案:

答案 0 :(得分:1)

我已经玩过一段时间了。您是否导入了GuzzleHttp包?如果是这样,这可能会帮助您:

use GuzzleHttp\Client;

public function __construct()
{
   $this->http_client = new Client();
}