From c0c0650feec31d5185a7fe28adf538603b1c3677 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 5 Dec 2025 23:11:35 +0100 Subject: [PATCH] Refactor ReCClient to use IHttpClientFactory Updated ReCClient to use IHttpClientFactory for improved resource management and testability. Added package references for `Microsoft.Extensions.Http`, `System.Net.Http`, and `System.Text.Json` to support HTTP client functionality and JSON serialization. Included `System.Xml.Linq` for potential XML-related operations. Updated constructor logic to create `HttpClient` instances via the factory pattern. --- src/ReC.Client/ReC.Client.csproj | 1 + src/ReC.Client/ReCClient.cs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ReC.Client/ReC.Client.csproj b/src/ReC.Client/ReC.Client.csproj index 6b41f2e..0b561b9 100644 --- a/src/ReC.Client/ReC.Client.csproj +++ b/src/ReC.Client/ReC.Client.csproj @@ -10,6 +10,7 @@ + diff --git a/src/ReC.Client/ReCClient.cs b/src/ReC.Client/ReCClient.cs index e680b72..e314da5 100644 --- a/src/ReC.Client/ReCClient.cs +++ b/src/ReC.Client/ReCClient.cs @@ -1,4 +1,6 @@ using System.Text.Json; +using System.Xml.Linq; + #if NETFRAMEWORK using System; using System.Net.Http; @@ -14,9 +16,9 @@ namespace ReC.Client private readonly HttpClient _http; private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }; - public ReCClient(HttpClient http) + public ReCClient(IHttpClientFactory httpClientFactory) { - _http = http ?? throw new ArgumentNullException(nameof(http)); + _http = httpClientFactory.CreateClient(); } ///