As previously discussed, we are using .NET's HttpClient as a disposable. This is not recommended as per https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/ and other sources.
We should look in to keeping an internal static HttpClient and use it where it makes sense. Take note that we cannot make assumptions on how this SDK will be used, so things such as DI that relies on registering services etc are probably out of scope, unless we provide our own HttpClient service that the user can register.
Alternatives of the top of my head:
- Keep an
internal static HttpClient and use it where applicable
- This is probably only applicable in some places, such as
CallAsync
- Let the user provide their own
HttpClient
- We do set headers prior to making requests, so we would probably have to do some house keeping with this
- Could the above lead to potential race conditions in multithreaded environments?
- Provide a service that the user can register for DI, and use that internally
- Not sure if this would provide any benefit over the previous point unless we can make such that the user can re-use their own
HttpClient
CC @brokenprogrammer - any thouights on this?
As previously discussed, we are using .NET's
HttpClientas a disposable. This is not recommended as per https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/ and other sources.We should look in to keeping an
internal static HttpClientand use it where it makes sense. Take note that we cannot make assumptions on how this SDK will be used, so things such as DI that relies on registering services etc are probably out of scope, unless we provide our ownHttpClientservice that the user can register.Alternatives of the top of my head:
internal static HttpClientand use it where applicableCallAsyncHttpClientHttpClientCC @brokenprogrammer - any thouights on this?