diff --git a/src/SendGrid/BaseClient.cs b/src/SendGrid/BaseClient.cs index aa3f59779..6baa01e47 100644 --- a/src/SendGrid/BaseClient.cs +++ b/src/SendGrid/BaseClient.cs @@ -42,7 +42,7 @@ public abstract class BaseClient : ISendGridClient /// /// A instance that defines the configuration settings to use with the client. /// Interface to the Twilio SendGrid REST API. - public BaseClient(BaseClientOptions options) + protected BaseClient(BaseClientOptions options) : this(httpClient: null, options) { } @@ -53,8 +53,8 @@ public BaseClient(BaseClientOptions options) /// Web proxy. /// A instance that defines the configuration settings to use with the client. /// Interface to the Twilio SendGrid REST API. - public BaseClient(IWebProxy webProxy, BaseClientOptions options) - : this(CreateHttpClientWithWebProxy(webProxy), options) + protected BaseClient(IWebProxy webProxy, BaseClientOptions options) + : this(CreateHttpClientWithWebProxy(webProxy, options), options) { } @@ -64,11 +64,11 @@ public BaseClient(IWebProxy webProxy, BaseClientOptions options) /// An optional HTTP client which may me injected in order to facilitate testing. /// A instance that defines the configuration settings to use with the client. /// Interface to the Twilio SendGrid REST API. - public BaseClient(HttpClient httpClient, BaseClientOptions options) + protected BaseClient(HttpClient httpClient, BaseClientOptions options) { this.options = options ?? throw new ArgumentNullException(nameof(options)); - this.client = httpClient ?? CreateHttpClientWithRetryHandler(); + this.client = httpClient ?? CreateHttpClientWithRetryHandler(options); if (this.options.RequestHeaders != null && this.options.RequestHeaders.TryGetValue(ContentType, out var contentType)) { this.MediaType = contentType; @@ -221,17 +221,18 @@ public async Task RequestAsync( cancellationToken: cancellationToken).ConfigureAwait(false); } - private static HttpClient CreateHttpClientWithRetryHandler() + private static HttpClient CreateHttpClientWithRetryHandler(BaseClientOptions options) { - return new HttpClient(new RetryDelegatingHandler(new ReliabilitySettings())); + return new HttpClient(new RetryDelegatingHandler(options.ReliabilitySettings)); } /// /// Create client with WebProxy if set. /// /// the WebProxy. + /// A instance that defines the configuration settings to use with the client. /// HttpClient with RetryDelegatingHandler and WebProxy if set. - private static HttpClient CreateHttpClientWithWebProxy(IWebProxy webProxy) + private static HttpClient CreateHttpClientWithWebProxy(IWebProxy webProxy, BaseClientOptions options) { if (webProxy != null) { @@ -242,13 +243,13 @@ private static HttpClient CreateHttpClientWithWebProxy(IWebProxy webProxy) UseDefaultCredentials = false, }; - var retryHandler = new RetryDelegatingHandler(httpClientHandler, new ReliabilitySettings()); + var retryHandler = new RetryDelegatingHandler(httpClientHandler, options.ReliabilitySettings); return new HttpClient(retryHandler); } else { - return CreateHttpClientWithRetryHandler(); + return CreateHttpClientWithRetryHandler(options); } } diff --git a/src/SendGrid/SendGridClient.cs b/src/SendGrid/SendGridClient.cs index f0579809e..7df69c870 100644 --- a/src/SendGrid/SendGridClient.cs +++ b/src/SendGrid/SendGridClient.cs @@ -55,6 +55,27 @@ public SendGridClient(string apiKey, string host = null, Dictionary + /// Initializes a new instance of the class. + /// + /// A instance that defines the configuration settings to use with the client. + /// Interface to the Twilio SendGrid REST API. + public SendGridClient(SendGridClientOptions options) + : base(options) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// An optional HTTP client which may me injected in order to facilitate testing. + /// A instance that defines the configuration settings to use with the client. + /// Interface to the Twilio SendGrid REST API. + public SendGridClient(HttpClient httpClient, SendGridClientOptions options) + : base(httpClient, options) + { + } + private static SendGridClientOptions buildOptions(string apiKey, string host, Dictionary requestHeaders, string version, string urlPath) { return new SendGridClientOptions