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

HttpClient should be used through IHttpClientFactory #115

Open
jamiehankins opened this issue Oct 16, 2024 · 2 comments
Open

HttpClient should be used through IHttpClientFactory #115

jamiehankins opened this issue Oct 16, 2024 · 2 comments

Comments

@jamiehankins
Copy link

This article You're using HttpClient wrong and it's destabilizing your software describes the problem. Their solution is to share a single instance of HttpClient.

A better solution is to implement IHttpClientFactory. Your ShipEngineClient constructor could take an instance of this. That would make it easy to adapt to applications that use dependency injection.

Here's the documentation for IHttpClientFactory.

@AnneOReilly
Copy link
Member

Thanks! We are reviewing this - it sounds like there were some changes earlier this year that should have resolved this issue, but we're going to double check and clear up anything we missed. We'll close this when that is merged in.

@joshuaflanagan
Copy link
Contributor

You are absolutely right that this was an issue, until our 2.2.1 release in June 2024.

We added the new constructor so that you could pass in an HttpClient instance that you manage yourself or obtain from IHttpClientFactory. We did not remove the existing constructors that create their own instance as we did not want to break compatibility. This is something we are considering for the 3.x release.

We also added a convenience method for registering a typed client that leverages IHttpClientFactory under the hood.

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

3 participants