From 8a58a6e9a342fb12c75766a3b1fd028b2d7c1e87 Mon Sep 17 00:00:00 2001 From: Alex Macocian Date: Fri, 16 Aug 2024 12:51:20 +0200 Subject: [PATCH] Improve HttpClient with client constructor --- SystemExtensions.NetStandard/Http/HttpClient.cs | 12 +++++++++++- .../SystemExtensions.NetStandard.csproj | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/SystemExtensions.NetStandard/Http/HttpClient.cs b/SystemExtensions.NetStandard/Http/HttpClient.cs index 1308ea8..8bbc872 100644 --- a/SystemExtensions.NetStandard/Http/HttpClient.cs +++ b/SystemExtensions.NetStandard/Http/HttpClient.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Extensions; +using System.IO; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; @@ -56,6 +57,15 @@ public sealed class HttpClient : IHttpClient, IDisposable 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() { this.LogInformation(string.Empty, "Canceling request"); diff --git a/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj b/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj index a39e722..a64ee22 100644 --- a/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj +++ b/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj @@ -7,7 +7,7 @@ LICENSE true System - 1.6.3 + 1.6.4 Alexandru Macocian https://github.com/AlexMacocian/SystemExtensions Extensions for the System namespace