From 0008fac1d275300cec389fc933766152342c6317 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Mon, 20 Apr 2026 10:29:17 +0200 Subject: [PATCH] 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. --- DbFirst.BlazorWebApp/Program.cs | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/DbFirst.BlazorWebApp/Program.cs b/DbFirst.BlazorWebApp/Program.cs index e06db92..9955b35 100644 --- a/DbFirst.BlazorWebApp/Program.cs +++ b/DbFirst.BlazorWebApp/Program.cs @@ -13,33 +13,17 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); var apiBaseUrl = builder.Configuration["ApiBaseUrl"]; -if (!string.IsNullOrWhiteSpace(apiBaseUrl)) +void ConfigureClient(HttpClient client) { - builder.Services.AddHttpClient(client => - { + if (!string.IsNullOrWhiteSpace(apiBaseUrl)) client.BaseAddress = new Uri(apiBaseUrl); - }); - builder.Services.AddHttpClient(client => - { - client.BaseAddress = new Uri(apiBaseUrl); - }); - builder.Services.AddHttpClient(client => - { - client.BaseAddress = new Uri(apiBaseUrl); - }); - builder.Services.AddHttpClient(client => - { - client.BaseAddress = new Uri(apiBaseUrl); - }); -} -else -{ - builder.Services.AddHttpClient(); - builder.Services.AddHttpClient(); - builder.Services.AddHttpClient(); - builder.Services.AddHttpClient(); } +builder.Services.AddHttpClient(ConfigureClient); +builder.Services.AddHttpClient(ConfigureClient); +builder.Services.AddHttpClient(ConfigureClient); +builder.Services.AddHttpClient(ConfigureClient); + var app = builder.Build(); // Configure the HTTP request pipeline.