.net core 在Net core 2.0类库中找不到System.Net.Http

.net core 在Net core 2.0类库中找不到System.Net.Http,.net-core,.net Core,我的net core解决方案的结构如下 API - web api Interfaces - class library Implementation - class library Models - class library 在API startup.cs中,我注册了如下服务: services.AddHttpClient(); 我在实施项目中有一个这样的类 using System.Net.Http; public IHttpClientFactory ihttpClientFact

我的net core解决方案的结构如下

API - web api
Interfaces - class library
Implementation - class library
Models - class library
在API startup.cs中,我注册了如下服务:

services.AddHttpClient();
我在实施项目中有一个这样的类

using System.Net.Http;

public IHttpClientFactory ihttpClientFactory;
    public class FooImplementation: IFoo {

      public void someFooMethod(){
           // here call client to fetch data from api
           // process this data
      }

    }

我想将IHttpClientFactory注入其中,但它抱怨找不到它。如何解决此错误?此外,这是基于项目结构将IHttpClientFactory传递到此类库的正确方法吗?

您必须仔细检查的文档,其中指出

命名空间:System.Net.Http

程序集:Microsoft.Extensions.Http.dll


这是要使用哪个NuGet包的提示,因此您应该添加一个包引用。

这取决于您的项目文件。在某些情况下,您需要显式的包引用。我确实通过nuget将System.Net.Http添加到实现项目中,但没有帮助。我将尝试Microsoft.Extensions.http解决此问题,谢谢@LexLi