Refactor HTTP client registration for API clients
Simplified registration of CatalogApiClient, DashboardApiClient, MassDataApiClient, and LayoutApiClient by introducing a ConfigureClient method. This method sets the BaseAddress if ApiBaseUrl is configured, removing the previous if-else logic and reducing code duplication.
This commit is contained in:
@@ -13,33 +13,17 @@ builder.Services.AddScoped<ThemeState>();
|
|||||||
builder.Services.AddScoped<BandLayoutService>();
|
builder.Services.AddScoped<BandLayoutService>();
|
||||||
|
|
||||||
var apiBaseUrl = builder.Configuration["ApiBaseUrl"];
|
var apiBaseUrl = builder.Configuration["ApiBaseUrl"];
|
||||||
if (!string.IsNullOrWhiteSpace(apiBaseUrl))
|
void ConfigureClient(HttpClient client)
|
||||||
{
|
{
|
||||||
builder.Services.AddHttpClient<CatalogApiClient>(client =>
|
if (!string.IsNullOrWhiteSpace(apiBaseUrl))
|
||||||
{
|
|
||||||
client.BaseAddress = new Uri(apiBaseUrl);
|
client.BaseAddress = new Uri(apiBaseUrl);
|
||||||
});
|
|
||||||
builder.Services.AddHttpClient<DashboardApiClient>(client =>
|
|
||||||
{
|
|
||||||
client.BaseAddress = new Uri(apiBaseUrl);
|
|
||||||
});
|
|
||||||
builder.Services.AddHttpClient<MassDataApiClient>(client =>
|
|
||||||
{
|
|
||||||
client.BaseAddress = new Uri(apiBaseUrl);
|
|
||||||
});
|
|
||||||
builder.Services.AddHttpClient<LayoutApiClient>(client =>
|
|
||||||
{
|
|
||||||
client.BaseAddress = new Uri(apiBaseUrl);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
builder.Services.AddHttpClient<CatalogApiClient>();
|
|
||||||
builder.Services.AddHttpClient<DashboardApiClient>();
|
|
||||||
builder.Services.AddHttpClient<MassDataApiClient>();
|
|
||||||
builder.Services.AddHttpClient<LayoutApiClient>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
builder.Services.AddHttpClient<CatalogApiClient>(ConfigureClient);
|
||||||
|
builder.Services.AddHttpClient<DashboardApiClient>(ConfigureClient);
|
||||||
|
builder.Services.AddHttpClient<MassDataApiClient>(ConfigureClient);
|
||||||
|
builder.Services.AddHttpClient<LayoutApiClient>(ConfigureClient);
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|||||||
Reference in New Issue
Block a user