symfony4 - 传递给服务的参数在 shopware 6 中给出依赖不存在服务错误
问题描述
我必须HttpClientInterface
在我的服务页面使用。所以我定义如下:
use Symfony\Contracts\HttpClient\HttpClientInterface;
public function __construct(HttpClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}
在我的services.xml
文件中,我也尝试传递参数并设置autowiring
<!-- SERVICES -->
<service id="SwagMasterBundle\Service\ProductManager" autowire="true" autoconfigure="true">
<argument id="Symfony\Contracts\HttpClient\HttpClientInterface" type="service" key="$httpClient"></argument>
</service>
但我收到错误:
The service "SwagMasterBundle\Service\ProductManager" has a dependency on a non-existent service "Symfony\Contracts\HttpClient\HttpClientInterface".
任何人都可以帮助我在这里做错了什么吗?
谢谢你。
解决方案
你不能指望一个接口,因为一个接口需要从一个具体的类中实现。所以,在你的情况下,你需要一个具体的对象——Symfony 服务是简单的对象。
请先参考面向对象的编程基础。
编辑:自动装配和定义给定的服务也没有意义。让框架确定所需的对象或自己做,但选择一个选项,而不是一次两个。
推荐阅读
- c# - PDFLib 使用 PDF 中未反映的 PANTONE 颜色将 SVG 转换为 PDF?
- vue.js - 无法让 VeeValidate 3.x 使用 VueSelect 处理自定义组件
- dialogflow-es - 我如何在最终用户与 Google Hangout 上的 Dialog flow ChatBot 交谈时获取用户电子邮件、姓名
- c++ - 是什么导致内存出现未处理的异常:堆栈溢出
- r - 如何在 R 中对数据框进行颜色格式化并将表格与表格标题和自定义文本一起导出为 pdf?
- macos - 相对框架路径、强化运行时和公证
- list - Haskell初学者问题,在定义中设置对
- python - 删除numpy数组中某个值的元素一次
- ffmpeg - ffmpeg 如何将静止图像放在完整的 vstack 上?
- mysql - GZIP 压缩对数据库图像有帮助吗?