Skip to content

Commit

Permalink
Lazy init the httpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
jaffinito committed Jun 19, 2024
1 parent c0bee03 commit bb56de8
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ private string CallWithWebRequest(Uri uri, string method, string vendorName, IEn
}
}
#else
// create a static HttpClient for use across all the vendor API calls
private static readonly HttpClient httpClient = new HttpClient
{
Timeout = TimeSpan.FromMilliseconds(WebReqeustTimeout)
};
private static readonly Lazy<HttpClient> httpClient = new Lazy<HttpClient>(() =>
new HttpClient
{
Timeout = TimeSpan.FromMilliseconds(WebReqeustTimeout)
});


private string CallWithHttpClient(Uri uri, string method, string vendorName, IEnumerable<string> headers = null)
{
Expand All @@ -112,7 +113,7 @@ private string CallWithHttpClient(Uri uri, string method, string vendorName, IEn
}
}

var response = httpClient.SendAsync(request).GetAwaiter().GetResult();
var response = httpClient.Value.SendAsync(request).GetAwaiter().GetResult();
if (!response.IsSuccessStatusCode)
{
var statusCode = response.StatusCode;
Expand Down

0 comments on commit bb56de8

Please sign in to comment.