-
Currently, I'm caching the HTTP clients on the basis of the base URL/named client and managing them through a factory class(singleton). While injecting them with I found out that IHttpClientFactory is managing the HttpClientHandler and reusing it. Also, we can configure the So my question do I need to cache my HTTP clients? Or I'm unnecessarily managing and caching them. And can I just go ahead and inject the Also, I got these guidelines
But after reading so many articles and theards I'm confused about what should I do and what should I not. I saw you are quite involved in quite of threads. So more I'm looking for advice what the best way to use We were having some conversation with @CarnaViire |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Following was the response of @CarnaViire
|
Beta Was this translation helpful? Give feedback.
-
If I'm injecting IHttpClientFactory to my scoped/transient services and creating a client by factory.CreateClient(name). HttpFactory will reuse the HttpMessageHandler internally and will respect the pool time that has been configured for the named client. Also disposing of the Httpclient will not harm in terms of resources as we have configured in the pool time. Am I correct? |
Beta Was this translation helpful? Give feedback.
-
Have you ever read this document? For ASP.NET Core apps, it's relatively simple to reach the best practice. I prefer the But if you're developing a client app, especially a web crawler, you have to deal with some situations by yourself and give up some guidance rules. I think the answer from @CarnaViire is clear and concrete enough . |
Beta Was this translation helpful? Give feedback.
If I'm injecting IHttpClientFactory to my scoped/transient services and creating a client by factory.CreateClient(name). HttpFactory will reuse the HttpMessageHandler internally and will respect the pool time that has been conf…