Skip to content

Use static HttpClient #24

Description

@GGAlanSmithee

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:

  1. Keep an internal static HttpClient and use it where applicable
    • This is probably only applicable in some places, such as CallAsync
  2. 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?
  3. 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?

Metadata

Metadata

Labels

enhancementNew feature or requesthelp wantedExtra attention is neededquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions