Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace HttpClient with IHttpClientFactory #6

Open
Ggeorgi98 opened this issue Sep 3, 2021 · 0 comments
Open

Replace HttpClient with IHttpClientFactory #6

Ggeorgi98 opened this issue Sep 3, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Ggeorgi98
Copy link

In your RestHelper, you use a shared instance of the HttpClient for sending the requests. This way we won't have the problem with the socket exhaustion since the instance is only one and it is reused but this can lead to another problem with not respecting DNS changes. The only way to apply the DNS changes to the client is by restarting the application so that the HttpClient instance is created again. This can be resolved if you use IHttpClientFactory. What is more, many articles and Microsoft docs recommend using the IHttpClientFactory for retrieving new HttpClient instances, coping with socket exhaustion problems, and the DNS one as well. Moreover, the IHttpClientFactory brings many optimizations in the performance and reliability of the HttpClient.
For reference:

  • 'You're (probably still) using HttpClient wrong and it is destabilizing your software', Josef Ottosson - link - you can check the section with the benchmarks and see that IHttpClientFactory is much better in performance than the HttpClient itself.
  • 'Pool HTTP connections with HttpClientFactory', ASP.NET Core Performance Best Practices - link
  • 'HTTPCLIENT CREATION AND DISPOSAL INTERNALS: SHOULD I DISPOSE OF HTTPCLIENT?', Steve Gordon - link
@josiasmontag josiasmontag added the enhancement New feature or request label Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants