Improve HttpClient with client constructor

This commit is contained in:
2024-08-16 12:51:20 +02:00
parent 3131558017
commit 8a58a6e9a3
2 changed files with 12 additions and 2 deletions
@@ -1,4 +1,5 @@
using System.IO; using System.Extensions;
using System.IO;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -56,6 +57,15 @@ public sealed class HttpClient<Tscope> : IHttpClient<Tscope>, IDisposable
this.scope = typeof(Tscope); this.scope = typeof(Tscope);
} }
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public HttpClient(
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
HttpClient httpClient)
{
this.httpClient = httpClient.ThrowIfNull(nameof(httpClient));
this.scope = typeof(Tscope);
}
public void CancelPendingRequests() public void CancelPendingRequests()
{ {
this.LogInformation(string.Empty, "Canceling request"); this.LogInformation(string.Empty, "Canceling request");
@@ -7,7 +7,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile> <PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RootNamespace>System</RootNamespace> <RootNamespace>System</RootNamespace>
<Version>1.6.3</Version> <Version>1.6.4</Version>
<Authors>Alexandru Macocian</Authors> <Authors>Alexandru Macocian</Authors>
<RepositoryUrl>https://github.com/AlexMacocian/SystemExtensions</RepositoryUrl> <RepositoryUrl>https://github.com/AlexMacocian/SystemExtensions</RepositoryUrl>
<Description>Extensions for the System namespace</Description> <Description>Extensions for the System namespace</Description>