Refactor API base URL config to use AppSettings object
Replaced direct configuration access for the API base URL with retrieval from an AppSettings object. Updated HttpClient configuration to use appSettings.ApiBaseUrl, improving consistency and maintainability. Existing AppSettings DI registration is retained.
This commit is contained in:
@@ -13,12 +13,12 @@ builder.Services.AddDevExpressBlazor(options => options.BootstrapVersion = Boots
|
||||
builder.Services.AddScoped<ThemeState>();
|
||||
builder.Services.AddScoped<BandLayoutService>();
|
||||
|
||||
var apiBaseUrl = builder.Configuration["ApiBaseUrl"];
|
||||
builder.Services.Configure<AppSettings>(builder.Configuration);
|
||||
var appSettings = builder.Configuration.Get<AppSettings>() ?? new AppSettings();
|
||||
void ConfigureClient(HttpClient client)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(apiBaseUrl))
|
||||
client.BaseAddress = new Uri(apiBaseUrl);
|
||||
if (!string.IsNullOrWhiteSpace(appSettings.ApiBaseUrl))
|
||||
client.BaseAddress = new Uri(appSettings.ApiBaseUrl);
|
||||
}
|
||||
|
||||
builder.Services.AddHttpClient<ICatalogApiClient, CatalogApiClient>(ConfigureClient);
|
||||
|
||||
Reference in New Issue
Block a user