cloudconvert / cloudconvert-dotnet

CloudConvert .NET SDK
Other
20 stars 15 forks source link

Replace HttpClient with IHttpClientFactory #6

Open Ggeorgi98 opened 3 years ago

Ggeorgi98 commented 3 years ago

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: