Add support for configurable options in ReCClient
Updated `ReCClient` to support dependency injection for `IOptions<ReCClientOptions>` and `ILogger`. Modified the constructor to include an optional `IOptions` parameter, allowing the use of configurable client options with default values when omitted. Updated API component initialization to pass `ReCClientOptions` for enhanced configuration. Added `Microsoft.Extensions.Logging` and `Microsoft.Extensions.Options` to `using` directives. Ensured compatibility with both `NETFRAMEWORK` and other target frameworks by updating constructor signatures accordingly.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using ReC.Client.Api;
|
using ReC.Client.Api;
|
||||||
@@ -57,21 +58,23 @@ namespace ReC.Client
|
|||||||
/// Initializes a new instance of the <see cref="ReCClient"/> class.
|
/// Initializes a new instance of the <see cref="ReCClient"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="httpClientFactory">The factory to create HttpClients.</param>
|
/// <param name="httpClientFactory">The factory to create HttpClients.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public ReCClient(IHttpClientFactory httpClientFactory, ILogger logger = null)
|
public ReCClient(IHttpClientFactory httpClientFactory, IOptions<ReCClientOptions> options = null, ILogger logger = null)
|
||||||
#else
|
#else
|
||||||
public ReCClient(IHttpClientFactory httpClientFactory, ILogger<ReCClient>? logger = null)
|
public ReCClient(IHttpClientFactory httpClientFactory, IOptions<ReCClientOptions>? options = null, ILogger<ReCClient>? logger = null)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
_http = httpClientFactory.CreateClient(ClientName);
|
_http = httpClientFactory.CreateClient(ClientName);
|
||||||
RecActions = new RecActionApi(_http, logger);
|
var opts = options?.Value ?? new ReCClientOptions();
|
||||||
Results = new ResultApi(_http, logger);
|
RecActions = new RecActionApi(_http, logger, opts);
|
||||||
Profiles = new ProfileApi(_http, logger);
|
Results = new ResultApi(_http, logger, opts);
|
||||||
EndpointAuth = new EndpointAuthApi(_http, logger);
|
Profiles = new ProfileApi(_http, logger, opts);
|
||||||
EndpointParams = new EndpointParamsApi(_http, logger);
|
EndpointAuth = new EndpointAuthApi(_http, logger, opts);
|
||||||
Endpoints = new EndpointsApi(_http, logger);
|
EndpointParams = new EndpointParamsApi(_http, logger, opts);
|
||||||
Common = new CommonApi(_http, logger);
|
Endpoints = new EndpointsApi(_http, logger, opts);
|
||||||
|
Common = new CommonApi(_http, logger, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Static
|
#region Static
|
||||||
|
|||||||
Reference in New Issue
Block a user