HttpClient Wrapper supports ignoring invalid/self-signed certs I'm using the following as a wrapper for the HtptClient because it doesn't implement an interface -- which makes mocking more difficult. This logic also supports invalid and self-signed certs. 

public class HttpClientWrapper : IHttpClient
{
    private readonly HttpClient _client;

    public Uri BaseAddress
    {
        get
        {
            return _client.BaseAddress;
        }

        set
        {
            _client.BaseAddress = value;
        }
    }

    public HttpRequestHeaders DefaultRequestHeaders
    {
        get
        {
            return _client.DefaultRequestHeaders;
        }
    }

    public HttpClientWrapper()
    {
        bool ignoreCertificateErrors = ConfigurationManager.AppSettings["IgnoreCertificateErrors"].ToBool();
        string environmentName = ConfigurationManager.AppSettings["EnvironmentName"];

        _client = new HttpClient();

        // If ignoreCertificateErrors config value is true, 
        // the setting ignores all Certificate validation errors in AppDomain, 
        // in every environment but PRODUCTION. 
        if (ignoreCertErrors &amp;&amp; environmentName.ToUpper() != "PRODUCTION")
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        }
    }

    public Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, String userOrProcessName)
    {
        IUnityContainer container = UnityCommon.GetContainer();
        ILogService logService = container.Resolve&lt;ILogService&gt;();

        logService.Log(ApplicationLogTypes.Debug, JsonConvert.SerializeObject(request), userOrProcessName);

        return _client.SendAsync(request);
    }

    #region IDisposable Support
    private bool disposedValue = false; // To detect redundant calls

    protected virtual void Dispose(bool disposing)
    {
        if (!disposedValue)
        {
            if (disposing &amp;&amp; _client != null)
            {
                _client.Dispose();
            }

            disposedValue = true;
        }
    }

    public void Dispose()
    {
        Dispose(true);
    }
    #endregion
}




using the following for interface:

public interface IHttpClient : IDisposable
{
    Uri BaseAddress { get; set; }

    HttpRequestHeaders DefaultRequestHeaders { get; }

    Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, String userOrProcessName);
}


Any suggestions?
bool ignoreCertificateErrors = ConfigurationManager.AppSettings["IgnoreCertificateErrors"].ToBool();
string environmentName = ConfigurationManager.AppSettings["EnvironmentName"];



These two lines I think shouldn't be there because with them, the wrapper is tigthly coupled to the app.config.

I see three possibilities how you can decouple the wrapper:


make both values constructor parameters if they shouldn't change
make them properties if they can
use the UnityCommon service locator that you use in the SendAsync method and let it resolve some ConfigProvider from which you can get both settings.





environmentName.ToUpper() != "PRODUCTION"



Usually in situations like this it's safer to use a  case insensitive comparison

environmentName.Equals("PRODUCTION", StringComparison.OrdinalIgnoreCase)