From 9535ebec0fb412e495d2a1456326708bb8da6494 Mon Sep 17 00:00:00 2001 From: Brice SCHUMACHER Date: Thu, 11 Sep 2025 22:47:23 +0200 Subject: [PATCH 1/4] fix : (RequestSender) Fixed usage of HttpClientFactory --- CHANGELOG.md | 9 +++- NotoriousClient.Sample/Program.cs | 3 +- NotoriousClient.sln | 50 ------------------- NotoriousClient.slnx | 14 ++++++ .../Extensions/ServiceCollectionExtensions.cs | 24 +++++++++ NotoriousClient/NotoriousClient.csproj | 2 +- NotoriousClient/Sender/RequestSender.cs | 8 +-- 7 files changed, 53 insertions(+), 57 deletions(-) delete mode 100644 NotoriousClient.sln create mode 100644 NotoriousClient.slnx create mode 100644 NotoriousClient/Extensions/ServiceCollectionExtensions.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index f6c2c77..011e04a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,4 +18,11 @@ ### 🐛 Bug Fixes -- Fixed a bug where the entire query string was encoded instead of only the query parameter keys and values. \ No newline at end of file +- Fixed a bug where the entire query string was encoded instead of only the query parameter keys and values. + +## 2.0.3 + +### 🛠 Technical + +- Fixed HttpClientFactory usage in default request sender +- Migrate to SLNX diff --git a/NotoriousClient.Sample/Program.cs b/NotoriousClient.Sample/Program.cs index 4bcdfbe..b5ac1bf 100644 --- a/NotoriousClient.Sample/Program.cs +++ b/NotoriousClient.Sample/Program.cs @@ -5,6 +5,7 @@ using NotoriousClient.Builder.Authentication; using NotoriousClient.Clients; using NotoriousClient.Converters; +using NotoriousClient.Extensions; using NotoriousClient.Sender; Console.WriteLine("Hello, World!"); @@ -24,7 +25,7 @@ var services = new ServiceCollection(); services.AddHttpClient(); -services.AddScoped((serviceProvider) => new RequestSender(serviceProvider.GetRequiredService())); +services.AddDefaultSender(); services.AddScoped((serviceProvider) => new UserClient(serviceProvider.GetRequiredService(), "http://my.api.com/")); ServiceProvider provider = services.BuildServiceProvider(); diff --git a/NotoriousClient.sln b/NotoriousClient.sln deleted file mode 100644 index feadff6..0000000 --- a/NotoriousClient.sln +++ /dev/null @@ -1,50 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.4.33110.190 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotoriousClient", "NotoriousClient\NotoriousClient.csproj", "{D0C70B6B-E6F3-4254-AC1B-BC523426E2A3}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotoriousClient.Sample", "NotoriousClient.Sample\NotoriousClient.Sample.csproj", "{B8A79A34-8CAE-4486-865B-956A633768E7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotoriousClient.Tests.Unit", "NotoriousClient.Tests.Unit\NotoriousClient.Tests.Unit.csproj", "{8F832E05-5A6C-4289-AB1E-2CD644E521DF}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" - ProjectSection(SolutionItems) = preProject - .github\workflows\prerelease.yml = .github\workflows\prerelease.yml - .github\workflows\release.yml = .github\workflows\release.yml - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{152A5ABF-D4EA-4E4E-B0C8-86791981137B}" - ProjectSection(SolutionItems) = preProject - CHANGELOG.md = CHANGELOG.md - LICENSE.txt = LICENSE.txt - README.md = README.md - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D0C70B6B-E6F3-4254-AC1B-BC523426E2A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D0C70B6B-E6F3-4254-AC1B-BC523426E2A3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D0C70B6B-E6F3-4254-AC1B-BC523426E2A3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D0C70B6B-E6F3-4254-AC1B-BC523426E2A3}.Release|Any CPU.Build.0 = Release|Any CPU - {B8A79A34-8CAE-4486-865B-956A633768E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B8A79A34-8CAE-4486-865B-956A633768E7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B8A79A34-8CAE-4486-865B-956A633768E7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B8A79A34-8CAE-4486-865B-956A633768E7}.Release|Any CPU.Build.0 = Release|Any CPU - {8F832E05-5A6C-4289-AB1E-2CD644E521DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8F832E05-5A6C-4289-AB1E-2CD644E521DF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8F832E05-5A6C-4289-AB1E-2CD644E521DF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8F832E05-5A6C-4289-AB1E-2CD644E521DF}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {02848B99-CEFB-46C3-A1D7-4251CB0B989F} - EndGlobalSection -EndGlobal diff --git a/NotoriousClient.slnx b/NotoriousClient.slnx new file mode 100644 index 0000000..0d753f0 --- /dev/null +++ b/NotoriousClient.slnx @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/NotoriousClient/Extensions/ServiceCollectionExtensions.cs b/NotoriousClient/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..2ca444d --- /dev/null +++ b/NotoriousClient/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,24 @@ +using Microsoft.Extensions.DependencyInjection; +using NotoriousClient.Clients; +using NotoriousClient.Sender; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NotoriousClient.Extensions +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddClient(this IServiceCollection services) where TClientImpl : BaseClient, TClient where TClient: class + { + return services.AddScoped(); + } + + public static IServiceCollection AddDefaultSender(this IServiceCollection services) + { + return services.AddScoped(); + } + } +} diff --git a/NotoriousClient/NotoriousClient.csproj b/NotoriousClient/NotoriousClient.csproj index 1e1c83a..3fffd8b 100644 --- a/NotoriousClient/NotoriousClient.csproj +++ b/NotoriousClient/NotoriousClient.csproj @@ -5,7 +5,7 @@ NotoriousClient enable enable - 2.0.2 + 2.0.3 README.md Brice SCHUMACHER https://github.com/Notorious-Coding/Notorious-Client/ diff --git a/NotoriousClient/Sender/RequestSender.cs b/NotoriousClient/Sender/RequestSender.cs index cf32ae7..a90d558 100644 --- a/NotoriousClient/Sender/RequestSender.cs +++ b/NotoriousClient/Sender/RequestSender.cs @@ -5,7 +5,7 @@ /// public class RequestSender : IRequestSender { - private readonly HttpClient _client; + private readonly IHttpClientFactory _factory; /// /// Initialize a new instance of . @@ -15,13 +15,13 @@ public class RequestSender : IRequestSender public RequestSender(IHttpClientFactory factory) { ArgumentNullException.ThrowIfNull(factory, nameof(factory)); - _client = factory.CreateClient(); + _factory = factory; } /// public async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken = default) { - HttpResponseMessage response = await _client.SendAsync(request, cancellationToken); + HttpResponseMessage response = await _factory.CreateClient().SendAsync(request, cancellationToken); return response; } @@ -29,7 +29,7 @@ public async Task SendAsync(HttpRequestMessage request, Can /// public HttpResponseMessage Send(HttpRequestMessage request) { - return _client.Send(request); + return _factory.CreateClient().Send(request); } } } From 56eaeae5b0f736d17ad4943643ff51c4f1e8ab88 Mon Sep 17 00:00:00 2001 From: Brice SCHUMACHER Date: Thu, 11 Sep 2025 22:50:30 +0200 Subject: [PATCH 2/4] clean : (Extensions) clean extensions test --- NotoriousClient.Sample/Program.cs | 9 ++++--- .../Extensions/ServiceCollectionExtensions.cs | 24 ------------------- 2 files changed, 4 insertions(+), 29 deletions(-) delete mode 100644 NotoriousClient/Extensions/ServiceCollectionExtensions.cs diff --git a/NotoriousClient.Sample/Program.cs b/NotoriousClient.Sample/Program.cs index b5ac1bf..7adedbd 100644 --- a/NotoriousClient.Sample/Program.cs +++ b/NotoriousClient.Sample/Program.cs @@ -1,11 +1,9 @@ // See https://aka.ms/new-console-template for more information using Microsoft.Extensions.DependencyInjection; + using NotoriousClient.Builder; -using NotoriousClient.Builder.Authentication; using NotoriousClient.Clients; -using NotoriousClient.Converters; -using NotoriousClient.Extensions; using NotoriousClient.Sender; Console.WriteLine("Hello, World!"); @@ -25,7 +23,8 @@ var services = new ServiceCollection(); services.AddHttpClient(); -services.AddDefaultSender(); +services.AddScoped((serviceProvider) => new RequestSender(serviceProvider.GetRequiredService())); + services.AddScoped((serviceProvider) => new UserClient(serviceProvider.GetRequiredService(), "http://my.api.com/")); ServiceProvider provider = services.BuildServiceProvider(); @@ -95,7 +94,7 @@ public TotoBuilder(string url, string route, Method method) : base(url, route, m public override HttpRequestMessage Build() { - HttpRequestMessage request = base.Build(); + HttpRequestMessage request = base.Build(); request.Headers.Add("TOTO", toto); return request; } diff --git a/NotoriousClient/Extensions/ServiceCollectionExtensions.cs b/NotoriousClient/Extensions/ServiceCollectionExtensions.cs deleted file mode 100644 index 2ca444d..0000000 --- a/NotoriousClient/Extensions/ServiceCollectionExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using NotoriousClient.Clients; -using NotoriousClient.Sender; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NotoriousClient.Extensions -{ - public static class ServiceCollectionExtensions - { - public static IServiceCollection AddClient(this IServiceCollection services) where TClientImpl : BaseClient, TClient where TClient: class - { - return services.AddScoped(); - } - - public static IServiceCollection AddDefaultSender(this IServiceCollection services) - { - return services.AddScoped(); - } - } -} From 2fd509dd0c0617b5752e76dbb68d45f18c7a10b5 Mon Sep 17 00:00:00 2001 From: Brice SCHUMACHER Date: Thu, 11 Sep 2025 22:56:35 +0200 Subject: [PATCH 3/4] chore : (prerelease+release) fix restore --- .github/workflows/prerelease.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index f5d8773..b069243 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -24,7 +24,7 @@ jobs: with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Restore dependencies - run: dotnet restore + run: dotnet restore NotoriousClient/NotoriousClient.csproj - name: Build run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore - name: Test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f43874..82b3fa2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Restore dependencies - run: dotnet restore + run: dotnet restore NotoriousClient/NotoriousClient.csproj - name: Build run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore - name: Test From 4ba18d8711b8e4d1e3e727c89dd547ca9e7deb80 Mon Sep 17 00:00:00 2001 From: Brice SCHUMACHER Date: Thu, 11 Sep 2025 23:00:06 +0200 Subject: [PATCH 4/4] chore : (release+prerelease) dotnet to 9 --- .github/workflows/prerelease.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index b069243..cc3d8ee 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -15,7 +15,7 @@ jobs: publish: env: CONFIGURATION: 'Release' - DOTNET_VERSION: '8.0' + DOTNET_VERSION: '9.0' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -24,7 +24,7 @@ jobs: with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Restore dependencies - run: dotnet restore NotoriousClient/NotoriousClient.csproj + run: dotnet restore - name: Build run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore - name: Test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 82b3fa2..b89179c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: publish: env: CONFIGURATION: 'Release' - DOTNET_VERSION: '8.0' + DOTNET_VERSION: '9.0' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -19,7 +19,7 @@ jobs: with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Restore dependencies - run: dotnet restore NotoriousClient/NotoriousClient.csproj + run: dotnet restore - name: Build run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore - name: Test