From 5f9e716ca6f65ef3311ecd99baf1c56514549ec1 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 5 Dec 2025 23:59:11 +0100 Subject: [PATCH] Enhance ReC.Client library with new features and cleanup - Added comprehensive XML documentation for `DependencyInjection` and `ReCClient` classes to improve code readability. - Introduced overload for `AddRecClient` to allow flexible `HttpClient` configuration. - Added static `BuildStaticClient` and `Create` methods for simplified client instantiation. - Marked synchronous `InvokeRecAction` method as obsolete to encourage asynchronous usage. - Updated `ReC.Client.csproj`: - Added `` property for XML doc generation. - Downgraded `Microsoft.Extensions.Http` to version 8.0.0. - Removed `System.Text.Json` package reference. - Removed `System.Text.Json` dependency from `ReCClient.cs`. - Generated unique `HttpClient` name for `ReCClient` instances. - Performed general code cleanup and improved method remarks. --- src/ReC.Client/DependencyInjection.cs | 15 +++++++++ src/ReC.Client/ReC.Client.csproj | 4 +-- src/ReC.Client/ReCClient.cs | 47 ++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/ReC.Client/DependencyInjection.cs b/src/ReC.Client/DependencyInjection.cs index 1b9c122..aa1ddd5 100644 --- a/src/ReC.Client/DependencyInjection.cs +++ b/src/ReC.Client/DependencyInjection.cs @@ -6,8 +6,17 @@ using System.Net.Http; namespace ReC.Client { + /// + /// Provides extension methods for setting up the ReC client in an . + /// public static class DependencyInjection { + /// + /// Adds and configures the for the to the specified + /// + /// The to add the services to. + /// The base URI of the ReC API. + /// An that can be used to configure the client. public static IHttpClientBuilder AddRecClient(this IServiceCollection services, string apiUri) { return services.AddHttpClient(ReCClient.ClientName, client => @@ -16,6 +25,12 @@ namespace ReC.Client }); } + /// + /// Adds and configures the for the to the specified + /// + /// The to add the services to. + /// An action to configure the . + /// An that can be used to configure the client. public static IHttpClientBuilder AddRecClient(this IServiceCollection services, Action configureClient) { return services.AddHttpClient(ReCClient.ClientName, configureClient); diff --git a/src/ReC.Client/ReC.Client.csproj b/src/ReC.Client/ReC.Client.csproj index 0b561b9..ea6f807 100644 --- a/src/ReC.Client/ReC.Client.csproj +++ b/src/ReC.Client/ReC.Client.csproj @@ -2,6 +2,7 @@ net462;net8.0 + bin\$(Configuration)\$(TargetFramework)\$(MSBuildProjectName).xml @@ -10,8 +11,7 @@ - + - diff --git a/src/ReC.Client/ReCClient.cs b/src/ReC.Client/ReCClient.cs index bde38c9..9a7faf1 100644 --- a/src/ReC.Client/ReCClient.cs +++ b/src/ReC.Client/ReCClient.cs @@ -1,5 +1,4 @@ -using System.Text.Json; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; #if NETFRAMEWORK using System; @@ -10,23 +9,36 @@ using System.Threading.Tasks; namespace ReC.Client { + /// + /// A client for interacting with the ReC API. + /// public class ReCClient { private readonly HttpClient _http; + /// + /// A unique name for the HttpClient used by the ReCClient. + /// public static readonly string ClientName = Guid.NewGuid().ToString(); + /// + /// Initializes a new instance of the class. + /// + /// The factory to create HttpClients. public ReCClient(IHttpClientFactory httpClientFactory) { _http = httpClientFactory.CreateClient(ClientName); } /// - /// POST api/RecAction/invoke/{profileId} + /// Asynchronously invokes a ReC action for a specific profile. /// - /// - /// - /// True if the request was successful, false otherwise + /// + /// This method sends a POST request to the api/RecAction/invoke/{profileId} endpoint. + /// + /// The ID of the profile to invoke the action for. + /// A token to cancel the asynchronous operation. + /// A that represents the asynchronous operation. The task result is if the request was successful; otherwise, . public async Task InvokeRecActionAsync(int profileId, CancellationToken cancellationToken = default) { var resp = await _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null, cancellationToken); @@ -34,10 +46,14 @@ namespace ReC.Client } /// - /// POST api/RecAction/invoke/{profileId} (Synchronous version) + /// Synchronously invokes a ReC action for a specific profile. /// - /// - /// True if the request was successful, false otherwise + /// + /// This method sends a POST request to the api/RecAction/invoke/{profileId} endpoint. + /// This is the synchronous version of . + /// + /// The ID of the profile to invoke the action for. + /// if the request was successful; otherwise, . [Obsolete("Use InvokeRecActionAsync instead to avoid potential deadlocks and improve performance.")] public bool InvokeRecAction(int profileId) { @@ -54,6 +70,14 @@ namespace ReC.Client private static IServiceProvider Provider = null; #endif + /// + /// Configures and builds the static for creating instances. + /// + /// + /// This method should only be called once during application startup. + /// + /// The base URI of the ReC API. + /// Thrown if the static provider has already been built. public static void BuildStaticClient(string apiUri) { if(Provider != null) @@ -66,6 +90,11 @@ namespace ReC.Client Provider = Services.BuildServiceProvider(); } + /// + /// Creates a new instance using the statically configured provider. + /// + /// A new instance of the . + /// Thrown if has not been called yet. public static ReCClient Create() { if (Provider == null)