[英]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
. 我很好奇在不依赖IserviceCollection
依赖注入的情况下使用HttpClientFactory
的最佳方法是什么。 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. 以前的示例都假设您正在使用DI,但是我正在使用.Net 4.6.2应用程序,并且我们的代码库尚未设置为使用它。
Is calling HttpClientFactory.Create()
a valid way to get a HttpClient for each request? 调用HttpClientFactory.Create()
是获取每个请求的HttpClient的有效方法吗? 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
) 还是我最好只使用HttpClient
的静态实例并确保每分钟关闭连接(使用ServicePointManager.DnsRefreshTimeout
和ServicePointManager.ConnectionLeaseTimeout
)
我最终只在代码中使用HttpClientFactory.Create()
,到目前为止看来还可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.