Refactor ReCClient API for async and DI compatibility

Updated `RecActions.InvokeAsync(...).Sync()` to align with migration guidelines, marking `Sync()` as `[Obsolete]` and recommending `async/await` for asynchronous patterns.

Enhanced `BuildStaticClient` methods to include an optional `configureOptions` parameter for flexible `ReCClientOptions` configuration. Added conditional compilation for nullable reference type compatibility across .NET Framework and modern .NET versions.

Updated `Services.AddRecClient` calls to support `configureOptions`. Retained `[Obsolete]` on static helpers to encourage dependency injection (`services.AddRecClient(...)`) for new code.

Revised migration notes to emphasize deprecation of synchronous methods, static helpers, and the importance of adopting modern async and DI patterns. Clarified changes to `GetAsync` methods, error handling with `ReCApiException`, and deserialization behavior.
This commit is contained in:
2026-05-20 15:11:14 +02:00
parent 983f3f76ad
commit e69bc9cdb9
2 changed files with 14 additions and 41 deletions

View File

@@ -93,14 +93,19 @@ namespace ReC.Client
/// This method should only be called once during application startup.
/// </remarks>
/// <param name="apiUri">The base URI of the ReC API.</param>
/// <param name="configureOptions">An optional callback to configure <see cref="ReCClientOptions"/>.</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(string apiUri)
#if NETFRAMEWORK
public static void BuildStaticClient(string apiUri, Action<ReCClientOptions> configureOptions = null)
#else
public static void BuildStaticClient(string apiUri, Action<ReCClientOptions>? configureOptions = null)
#endif
{
if(Provider != null)
throw new InvalidOperationException("Static Provider is already built.");
Services.AddRecClient(apiUri);
Services.AddRecClient(apiUri, configureOptions);
Provider = Services.BuildServiceProvider();
}
@@ -111,14 +116,19 @@ namespace ReC.Client
/// This method should only be called once during application startup.
/// </remarks>
/// <param name="configureClient">An action to configure the <see cref="HttpClient"/>.</param>
/// <param name="configureOptions">An optional callback to configure <see cref="ReCClientOptions"/>.</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 NETFRAMEWORK
public static void BuildStaticClient(Action<HttpClient> configureClient, Action<ReCClientOptions> configureOptions = null)
#else
public static void BuildStaticClient(Action<HttpClient> configureClient, Action<ReCClientOptions>? configureOptions = null)
#endif
{
if (Provider != null)
throw new InvalidOperationException("Static Provider is already built.");
Services.AddRecClient(configureClient);
Services.AddRecClient(configureClient, configureOptions);
Provider = Services.BuildServiceProvider();
}