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:
2026-05-19 19:20:28 +02:00
parent a43d1ebc20
commit e0c2aab2b1

View File

@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Net.Http;
using ReC.Client.Api;
@@ -57,21 +58,23 @@ namespace ReC.Client
/// Initializes a new instance of the <see cref="ReCClient"/> class.
/// </summary>
/// <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>
#if NETFRAMEWORK
public ReCClient(IHttpClientFactory httpClientFactory, ILogger logger = null)
public ReCClient(IHttpClientFactory httpClientFactory, IOptions<ReCClientOptions> options = null, ILogger logger = null)
#else
public ReCClient(IHttpClientFactory httpClientFactory, ILogger<ReCClient>? logger = null)
public ReCClient(IHttpClientFactory httpClientFactory, IOptions<ReCClientOptions>? options = null, ILogger<ReCClient>? logger = null)
#endif
{
_http = httpClientFactory.CreateClient(ClientName);
RecActions = new RecActionApi(_http, logger);
Results = new ResultApi(_http, logger);
Profiles = new ProfileApi(_http, logger);
EndpointAuth = new EndpointAuthApi(_http, logger);
EndpointParams = new EndpointParamsApi(_http, logger);
Endpoints = new EndpointsApi(_http, logger);
Common = new CommonApi(_http, logger);
var opts = options?.Value ?? new ReCClientOptions();
RecActions = new RecActionApi(_http, logger, opts);
Results = new ResultApi(_http, logger, opts);
Profiles = new ProfileApi(_http, logger, opts);
EndpointAuth = new EndpointAuthApi(_http, logger, opts);
EndpointParams = new EndpointParamsApi(_http, logger, opts);
Endpoints = new EndpointsApi(_http, logger, opts);
Common = new CommonApi(_http, logger, opts);
}
#region Static