From 87e1bb918774277e1370d95ed43207a3d5efb9f6 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 12 Dec 2025 12:42:39 +0100 Subject: [PATCH] Refactor: centralize HTTP client naming with Constants Introduced a Constants class to define a unique HttpClientName for HTTP client registration and usage. Updated DependencyInjection and InvokeRecActionCommandHandler to use this centralized name, improving consistency and reducing risk of name collisions. --- src/ReC.Application/Common/Constants.cs | 6 ++++++ src/ReC.Application/DependencyInjection.cs | 3 ++- .../RecActions/Commands/InvokeRecActionCommand.cs | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/ReC.Application/Common/Constants.cs diff --git a/src/ReC.Application/Common/Constants.cs b/src/ReC.Application/Common/Constants.cs new file mode 100644 index 0000000..0679ba1 --- /dev/null +++ b/src/ReC.Application/Common/Constants.cs @@ -0,0 +1,6 @@ +namespace ReC.Application.Common; + +public static class Constants +{ + public static readonly string HttpClientName = "HttpClient-" + Guid.NewGuid().ToString(); +} diff --git a/src/ReC.Application/DependencyInjection.cs b/src/ReC.Application/DependencyInjection.cs index 61981e0..e04b494 100644 --- a/src/ReC.Application/DependencyInjection.cs +++ b/src/ReC.Application/DependencyInjection.cs @@ -2,6 +2,7 @@ using MediatR; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using ReC.Application.Common; using ReC.Application.Common.Behaviors; using ReC.Application.Common.Options; using System.Reflection; @@ -35,7 +36,7 @@ public static class DependencyInjection cfg.LicenseKey = configOpt.LuckyPennySoftwareLicenseKey; }); - services.AddHttpClient("Default") + services.AddHttpClient(Constants.HttpClientName) .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { UseDefaultCredentials = false diff --git a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs index 7f72707..303d1d7 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs @@ -31,7 +31,7 @@ public class InvokeRecActionCommandHandler( { var action = request.Action; - using var http = clientFactory.CreateClient("Default"); + using var http = clientFactory.CreateClient(Constants.HttpClientName); if (action.RestType is null) throw new DataIntegrityException(