Add static BuildStaticClient method with Obsolete warning

A new static method `BuildStaticClient(Action<HttpClient> configureClient)`
was added to the `ReC.Client` namespace in `ReCClient.cs`. This method
configures and builds a static `IServiceProvider` for creating `ReCClient`
instances. It includes XML documentation detailing its purpose, usage,
and parameters, and warns that it should only be called once during
application startup.

The method accepts an `Action<HttpClient>` parameter for `HttpClient`
configuration and throws an `InvalidOperationException` if the static
provider is already built. It is marked `[Obsolete]` to encourage the
use of a local service collection instead of the static provider.

Additionally, the XML documentation for the `ReCClient` creation method
was updated to reference the new `BuildStaticClient` method.
This commit is contained in:
Developer 02 2025-12-06 00:13:50 +01:00
parent 470902911e
commit bdd78be66c

View File

@ -88,6 +88,24 @@ namespace ReC.Client
Provider = Services.BuildServiceProvider(); Provider = Services.BuildServiceProvider();
} }
/// <summary>
/// Configures and builds the static <see cref="IServiceProvider"/> for creating <see cref="ReCClient"/> instances.
/// </summary>
/// <remarks>
/// This method should only be called once during application startup.
/// </remarks>
/// <param name="configureClient">An action to configure the <see cref="HttpClient"/>.</param>
/// <exception cref="InvalidOperationException">Thrown if the static provider has already been built.</exception>
[Obsolete("Use a local service collection instead of the static provider.")]
public static void BuildStaticClient(Action<HttpClient> configureClient)
{
if (Provider != null)
throw new InvalidOperationException("Static Provider is already built.");
Services.AddRecClient(configureClient);
Provider = Services.BuildServiceProvider();
}
/// <summary> /// <summary>
/// Creates a new <see cref="ReCClient"/> instance using the statically configured provider. /// Creates a new <see cref="ReCClient"/> instance using the statically configured provider.
/// </summary> /// </summary>