Can I use HttpClientFactory in a .NET.core app which is not ASP.NET Core?

前端 未结 4 618
悲&欢浪女
悲&欢浪女 2021-01-07 21:45

I have read the popular blog post https://www.stevejgordon.co.uk/introduction-to-httpclientfactory-aspnetcore on using HttpClientFactory

To quote from it

4条回答
  •  醉酒成梦
    2021-01-07 22:40

    Just providing sample code for the first suggested approach in the accepted answer:

    services.AddHttpClient(); // where services is of type IServiceCollection
    

    and your class looks like:

    public class Foo : IFoo
    {
        private readonly HttpClient httpClient;
    
        public Consumer(HttpClient httpClient)
        {
            this.httpClient = httpClient;
        }
    }
    

提交回复
热议问题