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:
@@ -10,6 +10,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0" />
|
||||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
<PackageReference Include="System.Text.Json" Version="9.0.11" />
|
<PackageReference Include="System.Text.Json" Version="9.0.11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -14,9 +16,9 @@ namespace ReC.Client
|
|||||||
private readonly HttpClient _http;
|
private readonly HttpClient _http;
|
||||||
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true };
|
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>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user