public static void Main(string[] args) { HttpClientSingleton HttpClient = HttpClientSingleton.Instance(); var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup <Startup>() .UseApplicationInsights() .Build(); host.Run(); }
public static HttpClientSingleton Instance() { if (HttpClient == null) { // Allows threads to queue up to use the shared resource, prevents thread collision lock (mutex) { if (HttpClient == null) { HttpClient = new HttpClientSingleton(); // Sets the keep-alive header to false, we want to do this to ensure DNS entries are honoured // http://byterot.blogspot.co.uk/2016/07/singleton-httpclient-dns.html HttpClient.DefaultRequestHeaders.ConnectionClose = true; } } } return(HttpClient); }