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.
This commit is contained in:
Developer 02
2025-12-05 23:11:35 +01:00
parent 73059d4554
commit c0c0650fee
2 changed files with 5 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="9.0.11" />
</ItemGroup>

View File

@@ -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();
}
/// <summary>