From bdd78be66ce0f2097e54c92cef4350b972162715 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Sat, 6 Dec 2025 00:13:50 +0100 Subject: [PATCH] Add static BuildStaticClient method with Obsolete warning A new static method `BuildStaticClient(Action 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` 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. --- src/ReC.Client/ReCClient.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/ReC.Client/ReCClient.cs b/src/ReC.Client/ReCClient.cs index 92e6cb8..4249c15 100644 --- a/src/ReC.Client/ReCClient.cs +++ b/src/ReC.Client/ReCClient.cs @@ -88,6 +88,24 @@ namespace ReC.Client Provider = Services.BuildServiceProvider(); } + /// + /// Configures and builds the static for creating instances. + /// + /// + /// This method should only be called once during application startup. + /// + /// An action to configure the . + /// Thrown if the static provider has already been built. + [Obsolete("Use a local service collection instead of the static provider.")] + public static void BuildStaticClient(Action configureClient) + { + if (Provider != null) + throw new InvalidOperationException("Static Provider is already built."); + + Services.AddRecClient(configureClient); + Provider = Services.BuildServiceProvider(); + } + /// /// Creates a new instance using the statically configured provider. ///