/// <summary> /// Creates an IApiClient. /// </summary> /// <param name="settings"></param> /// <returns></returns> public IApiClient CreateApiClient(ApiClientFactorySettings settings) { ValidationHelper.ArgumentNotNull(settings, nameof(settings)); ValidationHelper.ArgumentNotNullOrWhiteSpace(settings.ConnectorApiUrl, nameof(settings.ConnectorApiUrl)); // get the api client generated by AutoRest from the swagger as a singleton object return(GetApiClient(settings)); }
/// <summary> /// Returns a singleton ApiClient instance /// </summary> /// <param name="settings"></param> /// <returns></returns> private IApiClient GetApiClient(ApiClientFactorySettings settings) { if (_apiClient == null) { lock (_apiClientSyncLock) { if (_apiClient == null) // this condition required for being thread-safe { if (settings.ServerCertificateValidation == false) { ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true; } // Support both the root site and /connector in the configuration var connectorApiUrl = new Uri(settings.ConnectorApiUrl); if (!settings.ConnectorApiUrl.Contains(ConnectorApiPrefix)) { connectorApiUrl = new Uri(connectorApiUrl, ConnectorApiPrefix); } #if NETSTANDARD2_0 if (settings.ServerCertificateValidation == false) { var certHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true }; _apiClient = new ApiClient(connectorApiUrl, new NotSpecifiedCredentials(), certHandler); } else { #endif _apiClient = new ApiClient(connectorApiUrl, new NotSpecifiedCredentials()); #if NETSTANDARD2_0 } #endif } } } return(_apiClient); }