How should I create my service HttpClient
to be instantiated once in the application to be able to reuse that instance throughout the application and avoid exhausting the sockets
?.
All this given that I am consuming a WebApi.
Currently I have my service like this:
public static HttpClient GenerateClient()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://0.0.0.0:0000/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(string.IsNullOrEmpty(token);
return client;
}