I am using System.Net.HttpClient (.Net 4.5) in my MVC4 project. I know that a single instance of HttpClient can be used for all Http requests across the web app. Here is my implementation of the HttpClient singleton which should return the single instance every time.
public sealed class HttpClientInstance: HttpClient
{
// singleton instance
private static readonly HttpClientInstance instance = new HttpClientInstance();
static HttpClientInstance() { }
private HttpClientInstance() : base() {
Timeout = TimeSpan.FromMilliseconds(15000)));
}
/// <summary>
/// Returns the singleton instance of HttpClient
/// </summary>
public static HttpClient Instance
{
get
{
return instance;
}
}
}
Do you see any issues with this?
I know I could possibly use Ninject to inject the dependency in singleton scope but that is besides the point.