.net 适用于'类型的构造函数;ApplicationInventory.Services.ServerInventoryService';找不到

.net 适用于'类型的构造函数;ApplicationInventory.Services.ServerInventoryService';找不到,.net,asp.net-core,interface,dotnet-httpclient,.net,Asp.net Core,Interface,Dotnet Httpclient,我正在尝试为我的ASP.NETCore2.2应用程序的特定端点创建一个控制器和常规函数都可以访问的服务。每当我尝试注入HttpClient类时,就会在到达函数之前发生错误/ 我已经按照文档中所示设置了startup.cs,并将构造函数输入减少到了HttpClient,因此我知道这就是问题的根源所在。我已经用我能想到的每一种方法将HttpClient添加到Startup.cs类的configure services部分 Startup.cs public void Configur

我正在尝试为我的ASP.NETCore2.2应用程序的特定端点创建一个控制器和常规函数都可以访问的服务。每当我尝试注入HttpClient类时,就会在到达函数之前发生错误/

我已经按照文档中所示设置了startup.cs,并将构造函数输入减少到了HttpClient,因此我知道这就是问题的根源所在。我已经用我能想到的每一种方法将HttpClient添加到Startup.cs类的configure services部分

Startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            ...
                        // adding ability to make basic http calls 
            services.AddHttpClient<IServerInventoryService, ServerInventoryService>(c =>
            {
                c.BaseAddress = new Uri("https://serverinventory.cooperatorsgroup.ca/api/");
            }).ConfigurePrimaryHttpMessageHandler(() =>
            {
                return new HttpClientHandler()
                {
                    AllowAutoRedirect = false,
                    UseDefaultCredentials = true
                };
            });

}
每次呼叫服务结果都是:


“InvalidOperationException:找不到类型为'ApplicationInventory.Services.ServerInventoryService'的合适构造函数。请确保该类型是具体的,并且为公共构造函数的所有参数注册了服务。”

是否有任何演示重现您的问题?无法用当前代码重现您的问题。不幸的是,我无法提供更多代码,但这似乎与情况有关。如果代码无法重现您的问题,这是无可奈何的,您可以通过新的.net核心项目检查是否可以用您的当前代码生成此问题。您好,@Grady Van Pinxteren您发现这个问题了吗?嘿,是的,我相信问题出在另一段代码上。是否有任何演示来重现您的问题?无法用当前代码重现您的问题。不幸的是,我无法提供更多代码,但这似乎与情况有关。如果代码无法重现您的问题,这是无可奈何的,您可以通过新的.net核心项目检查是否可以用您的当前代码生成此问题。您好,@Grady Van Pinxteren您发现这个问题了吗?嘿,是的,我相信问题出在另一段代码上。
       private ILogger<ServerInventoryApiController> logger;
        private IHttpClientFactory clientFactory;
        private readonly IServerInventoryService ServerInventoryService;
        public ServerInventoryApiController(ILogger<ServerInventoryApiController> _logger, IServerInventoryService _service, IHttpClientFactory httpClientFactory)
        {
            ServerInventoryService = _service;
            logger = _logger;
            clientFactory = httpClientFactory;
        }
  public class ServerInventoryService : IServerInventoryService
    {
        private HttpClient client;
        //        private readonly IConfiguration configuration;

        public ServerInventoryService(HttpClient httpClient)
        {
            client = httpClient;
        }