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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user