HAKAN'S REQUIREMENT - Refactor API base URL configuration structure

Replaced ApiBaseUrl and DataApiBaseUrl with BaseUrl, ApiDefaultUrl, and service-specific configuration sections (AuthService, UserManagerService, DbFirstService). Updated AppSettings and all code references to use the new structure. Revised logic for HTTP client base URL selection to prefer service-specific settings. Updated appsettings files and added an example configuration for clarity and maintainability.
This commit is contained in:
OlgunR
2026-05-12 16:34:26 +02:00
parent 1ad267e409
commit 91ee044b73
7 changed files with 83 additions and 25 deletions

View File

@@ -28,7 +28,7 @@ public static class DashboardConfiguratorFactory
} }
var dashboardBaseUrl = configuration["Dashboard:BaseUrl"] var dashboardBaseUrl = configuration["Dashboard:BaseUrl"]
?? configuration["ApiBaseUrl"] ?? configuration["BaseUrl"]
?? configuration["ASPNETCORE_URLS"]?.Split(';', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? configuration["ASPNETCORE_URLS"]?.Split(';', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault()
?? "https://localhost:7204"; ?? "https://localhost:7204";

View File

@@ -2,6 +2,15 @@
public class AppSettings public class AppSettings
{ {
public string ApiBaseUrl { get; set; } = string.Empty; public string BaseUrl { get; set; } = string.Empty;
public string DataApiBaseUrl { get; set; } = string.Empty; public string ApiDefaultUrl { get; set; } = string.Empty;
public AuthServiceSettings AuthService { get; set; } = new();
}
public class AuthServiceSettings
{
public string BaseUrl { get; set; } = string.Empty;
public string Login { get; set; } = string.Empty;
public string Logout { get; set; } = string.Empty;
public string Check { get; set; } = string.Empty;
} }

View File

@@ -45,8 +45,8 @@
private string SelectedDashboardId { get; set; } = string.Empty; private string SelectedDashboardId { get; set; } = string.Empty;
private string DashboardKey => $"{SelectedDashboardId}-{(IsDesigner ? "designer" : "viewer")}"; private string DashboardKey => $"{SelectedDashboardId}-{(IsDesigner ? "designer" : "viewer")}";
private string DashboardEndpoint => $"{AppSettingsOptions.Value.ApiBaseUrl.TrimEnd('/')}/api/dashboard"; private string DashboardEndpoint => $"{AppSettingsOptions.Value.BaseUrl.TrimEnd('/')}/api/dashboard";
private string HubEndpoint => $"{AppSettingsOptions.Value.ApiBaseUrl.TrimEnd('/')}/hubs/dashboards"; private string HubEndpoint => $"{AppSettingsOptions.Value.BaseUrl.TrimEnd('/')}/hubs/dashboards";
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {

View File

@@ -33,25 +33,28 @@ static HttpClient CreateHttpClientWithCookies(CookieContainer cookieContainer, s
builder.Services.AddScoped<IAuthApiClient>(sp => builder.Services.AddScoped<IAuthApiClient>(sp =>
{ {
var cc = sp.GetRequiredService<CookieContainer>(); var cc = sp.GetRequiredService<CookieContainer>();
var client = CreateHttpClientWithCookies(cc, appSettings.ApiBaseUrl); var authBaseUrl = !string.IsNullOrWhiteSpace(appSettings.AuthService.BaseUrl)
? appSettings.AuthService.BaseUrl
: appSettings.BaseUrl;
var client = CreateHttpClientWithCookies(cc, authBaseUrl);
return new AuthApiClient(client, sp.GetRequiredService<AuthService>(), cc); return new AuthApiClient(client, sp.GetRequiredService<AuthService>(), cc);
}); });
var dataApiBaseUrl = !string.IsNullOrWhiteSpace(appSettings.DataApiBaseUrl) var apiDefaultUrl = !string.IsNullOrWhiteSpace(appSettings.ApiDefaultUrl)
? appSettings.DataApiBaseUrl ? appSettings.ApiDefaultUrl
: appSettings.ApiBaseUrl; : appSettings.BaseUrl;
builder.Services.AddScoped<ICatalogApiClient>(sp => builder.Services.AddScoped<ICatalogApiClient>(sp =>
new CatalogApiClient(CreateHttpClientWithCookies(sp.GetRequiredService<CookieContainer>(), dataApiBaseUrl))); new CatalogApiClient(CreateHttpClientWithCookies(sp.GetRequiredService<CookieContainer>(), apiDefaultUrl)));
builder.Services.AddScoped<IDashboardApiClient>(sp => builder.Services.AddScoped<IDashboardApiClient>(sp =>
new DashboardApiClient(CreateHttpClientWithCookies(sp.GetRequiredService<CookieContainer>(), dataApiBaseUrl))); new DashboardApiClient(CreateHttpClientWithCookies(sp.GetRequiredService<CookieContainer>(), apiDefaultUrl)));
builder.Services.AddScoped<IMassDataApiClient>(sp => builder.Services.AddScoped<IMassDataApiClient>(sp =>
new MassDataApiClient(CreateHttpClientWithCookies(sp.GetRequiredService<CookieContainer>(), dataApiBaseUrl))); new MassDataApiClient(CreateHttpClientWithCookies(sp.GetRequiredService<CookieContainer>(), apiDefaultUrl)));
builder.Services.AddScoped<ILayoutApiClient>(sp => builder.Services.AddScoped<ILayoutApiClient>(sp =>
new LayoutApiClient(CreateHttpClientWithCookies(sp.GetRequiredService<CookieContainer>(), dataApiBaseUrl))); new LayoutApiClient(CreateHttpClientWithCookies(sp.GetRequiredService<CookieContainer>(), apiDefaultUrl)));
var app = builder.Build(); var app = builder.Build();

View File

@@ -5,12 +5,25 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"ApiBaseUrl": "http://172.24.12.39:9090/", "ApiDefaultUrl": "https://localhost:7204/",
"DataApiBaseUrl": "https://localhost:7204/", "AuthService": {
"BaseUrl": "http://172.24.12.39:9090/",
"Login": "/api/Auth/db-first/login",
"Logout": "auth/logout",
"Check": "auth/check"
},
"UserManagerService": {
"BaseUrl": null,
"GetUserInfo": "user/info",
"UpdateUserInfo": "user/update"
},
"DbFirstService": {
"BaseUrl": "https://localhost:7204/",
"GetData": "dbfirst/data",
"UpdateData": "dbfirst/update"
},
"BrowserLink": { "BrowserLink": {
"Enabled": false "Enabled": false
}, },
"DetailedErrors": true "DetailedErrors": true
} }

View File

@@ -0,0 +1,19 @@
{
"ApiDefaultUrl": "https://localhost:7204/",
"AuthService": {
"BaseUrl": "http://172.24.12.39:9090/",
"Login": "/api/Auth/db-first/login",
"Logout": "auth/logout",
"Check": "auth/check"
},
"UserManagerService": {
"BaseUrl": null,
"GetUserInfo": "user/info",
"UpdateUserInfo": "user/update"
},
"DbFirstService": {
"BaseUrl": "https://localhost:7204/",
"GetData": "dbfirst/data",
"UpdateData": "dbfirst/update"
}
}

View File

@@ -1,11 +1,25 @@
{ {
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
},
"ApiDefaultUrl": "https://localhost:7204/",
"AuthService": {
"BaseUrl": null,
"Login": "auth/login",
"Logout": "auth/logout",
"Check": "auth/check"
},
"UserManagerService": {
"BaseUrl": null,
"GetUserInfo": "user/info",
"UpdateUserInfo": "user/update"
}, },
"ApiBaseUrl": "http://172.24.12.39:9090/", "DbFirstService": {
"DataApiBaseUrl": "https://localhost:7204/", "BaseUrl": null,
"AllowedHosts": "*" "GetData": "dbfirst/data",
"UpdateData": "dbfirst/update"
}
} }