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.
This commit is contained in:
6
src/ReC.Application/Common/Constants.cs
Normal file
6
src/ReC.Application/Common/Constants.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ReC.Application.Common;
|
||||
|
||||
public static class Constants
|
||||
{
|
||||
public static readonly string HttpClientName = "HttpClient-" + Guid.NewGuid().ToString();
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user