简体   繁体   中英

HttpClientFactory without IServiceCollection (.net framework 4.6.2)

I am curious on what is the best way to use HttpClientFactory without relying on Dependency Injection from IserviceCollection . Ever example assumes you are using DI, but I am working on a .Net 4.6.2 app and our code base is not set up to use it.

Is calling HttpClientFactory.Create() a valid way to get a HttpClient for each request? Should I be disposing it? Or am I better off just using a static instance of HttpClient and ensure that connection gets closed every min (using ServicePointManager.DnsRefreshTimeout and ServicePointManager.ConnectionLeaseTimeout )

我最终只在代码中使用HttpClientFactory.Create() ,到目前为止看来还可以。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM