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

Bad usage of the HttpClient #55

Open
ghost opened this issue Oct 20, 2023 · 0 comments
Open

Bad usage of the HttpClient #55

ghost opened this issue Oct 20, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Oct 20, 2023

Your implementation of the usage from the HttpClient is bad.

Unfortunately, correct lifetime management of HttpClient is one of the biggest gotchas in .NET, MS really needs to fix it: it's unreasonable to expect people to understand concepts like socket-exhaustion and such when all they want to do is make a web-request every 15 minutes in a Windows Service, for example.

So a better solution is using a IHttpClientFactory to create the HttpClient for each single request. Maybe you can realize this with HttpClientFactory.CreateHttpClient.

This would be a better solution, but there are still a lot of issues with it:

  1. There is no way for me to set a UserClient (ApplicationName) for the HttpClient.
  2. There is no way for me to configure a Proxy server.
  3. There is no way for me to log HTTP requests.

To let me do all of this, it would be nice if you would implement a Callback function, how I can create the HttpClient by myself.

You could realize this, for example, with a static event in your Helpers.cs file. If you invoke this event before each HttpClient usage, I could create my own HttpClient every time fresh. And if I don't register to the event, you could use your static HttpClient furthermore.

This solution should be not a lot of work for you.

If you are interested, I would realize this and offer with a Pull Request to you.

What do you thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants