Files
ReC/src/ReC.Client/StaticBuildConfiguration.cs
TekH 9e1bee9ea3 Refactor and enhance static ReCClient configuration
Introduced a new `BuildStaticClient(Action<StaticBuildConfiguration>)` method for flexible and detailed static `IServiceProvider` configuration. Added the `StaticBuildConfiguration` class to encapsulate optional settings like `BaseAddress`, `ConfigureClient`, `Logger`, and more.

Refactored existing `BuildStaticClient` overloads to use the new method, ensuring consistency and reducing duplication. Added support for optional `ILogger` instances and improved validation to enforce proper configuration.

Marked existing `BuildStaticClient` methods as obsolete, recommending the new method. Enhanced thread-safety using `Interlocked.CompareExchange`. Updated XML documentation and added conditional compilation for `NETFRAMEWORK` compatibility.

These changes improve maintainability, usability, and alignment with modern .NET practices.
2026-05-21 08:32:04 +02:00

64 lines
2.1 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Net.Http;
namespace ReC.Client
{
/// <summary>
/// Configuration object for <see cref="ReCClient.BuildStaticClient(Action{StaticBuildConfiguration})"/>.
/// Groups all optional settings for the static <see cref="ReCClient"/> bootstrap path.
/// </summary>
/// <remarks>
/// Either <see cref="BaseAddress"/> or <see cref="ConfigureClient"/> must be set; setting both at the same time is not allowed.
/// </remarks>
public class StaticBuildConfiguration
{
/// <summary>
/// Base URI of the ReC API. Mutually exclusive with <see cref="ConfigureClient"/>.
/// </summary>
#if NETFRAMEWORK
public string BaseAddress { get; set; }
#else
public string? BaseAddress { get; set; }
#endif
/// <summary>
/// Callback that configures the underlying <see cref="HttpClient"/>. Mutually exclusive with <see cref="BaseAddress"/>.
/// </summary>
#if NETFRAMEWORK
public Action<HttpClient> ConfigureClient { get; set; }
#else
public Action<HttpClient>? ConfigureClient { get; set; }
#endif
/// <summary>
/// Optional callback to configure <see cref="ReCClientOptions"/>.
/// </summary>
#if NETFRAMEWORK
public Action<ReCClientOptions> ConfigureOptions { get; set; }
#else
public Action<ReCClientOptions>? ConfigureOptions { get; set; }
#endif
/// <summary>
/// Optional logger instance to be registered as a singleton in the internal service collection.
/// </summary>
#if NETFRAMEWORK
public ILogger Logger { get; set; }
#else
public ILogger<ReCClient>? Logger { get; set; }
#endif
/// <summary>
/// Optional callback for additional service registrations on the internal <see cref="IServiceCollection"/>
/// (e.g. <c>services.AddLogging(...)</c> or custom dependencies).
/// </summary>
#if NETFRAMEWORK
public Action<IServiceCollection> ConfigureServices { get; set; }
#else
public Action<IServiceCollection>? ConfigureServices { get; set; }
#endif
}
}