0

我在 asp.net core 3.1 项目中有以下代码:

IArticleService.cs

namespace API.Interfaces
{
    public interface IArticleService
    {
        Task<ArticleDTO> GetArticleAsync(int articleId, int countryId, string userCookieId);
    }
}

文章服务.cs

namespace API.Services
{
    public class ArticleService : IArticleService
    {
        private readonly IOptions<UrlsConfig> _urlConfig;
        private readonly HttpClient _httpClient;
        private readonly ILogger<ArticleService> _logger;

        public ArticleService(HttpClient httpClient, IOptions<UrlsConfig> urlConfig, ILogger<ArticleService> logger)
        {
            _urlConfig = urlConfig;
            _httpClient = httpClient;
            _logger = logger;
        }
        public async Task<ArticleDTO> GetArticleAsync(int articleId, int countryId, string userCookieId)
        {
            throw new System.NotImplementedException();
        }
    }
}

ProjectServiceCollectionExtensions.cs

public static IServiceCollection AddHttpClientDependencies(this IServiceCollection services)
{
    return services.AddHttpClient<IArticleService, ArticleService>();
}

启动.cs

公共虚拟 void ConfigureServices(IServiceCollection services) => services.AddHttpClientDependencies()

它抛出一个错误:

错误 CS0266 无法将类型“Microsoft.Extensions.DependencyInjection.IHttpClientBuilder”隐式转换为“Microsoft.Extensions.DependencyInjection.IServiceCollection”。存在显式转换(您是否缺少演员表?)

任何人都可以在这里为我提供一些解决此问题的指导吗?

4

0 回答 0