From 91ee044b735845226e51fce88deab6e61ee718ef Mon Sep 17 00:00:00 2001 From: OlgunR Date: Tue, 12 May 2026 16:34:26 +0200 Subject: [PATCH] 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. --- .../DashboardConfiguratorFactory.cs | 2 +- DbFirst.BlazorWebApp/AppSettings.cs | 13 ++++++-- .../Components/Pages/Dashboard.razor | 4 +-- DbFirst.BlazorWebApp/Program.cs | 19 +++++++----- .../appsettings.Development.json | 21 ++++++++++--- DbFirst.BlazorWebApp/appsettings.Example.json | 19 ++++++++++++ DbFirst.BlazorWebApp/appsettings.json | 30 ++++++++++++++----- 7 files changed, 83 insertions(+), 25 deletions(-) create mode 100644 DbFirst.BlazorWebApp/appsettings.Example.json diff --git a/DbFirst.API/Dashboards/DashboardConfiguratorFactory.cs b/DbFirst.API/Dashboards/DashboardConfiguratorFactory.cs index abf97b4..423357a 100644 --- a/DbFirst.API/Dashboards/DashboardConfiguratorFactory.cs +++ b/DbFirst.API/Dashboards/DashboardConfiguratorFactory.cs @@ -28,7 +28,7 @@ public static class DashboardConfiguratorFactory } var dashboardBaseUrl = configuration["Dashboard:BaseUrl"] - ?? configuration["ApiBaseUrl"] + ?? configuration["BaseUrl"] ?? configuration["ASPNETCORE_URLS"]?.Split(';', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? "https://localhost:7204"; diff --git a/DbFirst.BlazorWebApp/AppSettings.cs b/DbFirst.BlazorWebApp/AppSettings.cs index 3841630..a5de779 100644 --- a/DbFirst.BlazorWebApp/AppSettings.cs +++ b/DbFirst.BlazorWebApp/AppSettings.cs @@ -2,6 +2,15 @@ public class AppSettings { - public string ApiBaseUrl { get; set; } = string.Empty; - public string DataApiBaseUrl { get; set; } = string.Empty; + public string BaseUrl { 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; } \ No newline at end of file diff --git a/DbFirst.BlazorWebApp/Components/Pages/Dashboard.razor b/DbFirst.BlazorWebApp/Components/Pages/Dashboard.razor index 0284f19..6734220 100644 --- a/DbFirst.BlazorWebApp/Components/Pages/Dashboard.razor +++ b/DbFirst.BlazorWebApp/Components/Pages/Dashboard.razor @@ -45,8 +45,8 @@ private string SelectedDashboardId { get; set; } = string.Empty; private string DashboardKey => $"{SelectedDashboardId}-{(IsDesigner ? "designer" : "viewer")}"; - private string DashboardEndpoint => $"{AppSettingsOptions.Value.ApiBaseUrl.TrimEnd('/')}/api/dashboard"; - private string HubEndpoint => $"{AppSettingsOptions.Value.ApiBaseUrl.TrimEnd('/')}/hubs/dashboards"; + private string DashboardEndpoint => $"{AppSettingsOptions.Value.BaseUrl.TrimEnd('/')}/api/dashboard"; + private string HubEndpoint => $"{AppSettingsOptions.Value.BaseUrl.TrimEnd('/')}/hubs/dashboards"; protected override async Task OnInitializedAsync() { diff --git a/DbFirst.BlazorWebApp/Program.cs b/DbFirst.BlazorWebApp/Program.cs index 0f7c66f..b3e959d 100644 --- a/DbFirst.BlazorWebApp/Program.cs +++ b/DbFirst.BlazorWebApp/Program.cs @@ -33,25 +33,28 @@ static HttpClient CreateHttpClientWithCookies(CookieContainer cookieContainer, s builder.Services.AddScoped(sp => { var cc = sp.GetRequiredService(); - 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(), cc); }); -var dataApiBaseUrl = !string.IsNullOrWhiteSpace(appSettings.DataApiBaseUrl) - ? appSettings.DataApiBaseUrl - : appSettings.ApiBaseUrl; +var apiDefaultUrl = !string.IsNullOrWhiteSpace(appSettings.ApiDefaultUrl) + ? appSettings.ApiDefaultUrl + : appSettings.BaseUrl; builder.Services.AddScoped(sp => - new CatalogApiClient(CreateHttpClientWithCookies(sp.GetRequiredService(), dataApiBaseUrl))); + new CatalogApiClient(CreateHttpClientWithCookies(sp.GetRequiredService(), apiDefaultUrl))); builder.Services.AddScoped(sp => - new DashboardApiClient(CreateHttpClientWithCookies(sp.GetRequiredService(), dataApiBaseUrl))); + new DashboardApiClient(CreateHttpClientWithCookies(sp.GetRequiredService(), apiDefaultUrl))); builder.Services.AddScoped(sp => - new MassDataApiClient(CreateHttpClientWithCookies(sp.GetRequiredService(), dataApiBaseUrl))); + new MassDataApiClient(CreateHttpClientWithCookies(sp.GetRequiredService(), apiDefaultUrl))); builder.Services.AddScoped(sp => - new LayoutApiClient(CreateHttpClientWithCookies(sp.GetRequiredService(), dataApiBaseUrl))); + new LayoutApiClient(CreateHttpClientWithCookies(sp.GetRequiredService(), apiDefaultUrl))); var app = builder.Build(); diff --git a/DbFirst.BlazorWebApp/appsettings.Development.json b/DbFirst.BlazorWebApp/appsettings.Development.json index 545137b..e8c02e1 100644 --- a/DbFirst.BlazorWebApp/appsettings.Development.json +++ b/DbFirst.BlazorWebApp/appsettings.Development.json @@ -5,12 +5,25 @@ "Microsoft.AspNetCore": "Warning" } }, - "ApiBaseUrl": "http://172.24.12.39:9090/", - "DataApiBaseUrl": "https://localhost:7204/", + "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" + }, "BrowserLink": { "Enabled": false }, "DetailedErrors": true } - - diff --git a/DbFirst.BlazorWebApp/appsettings.Example.json b/DbFirst.BlazorWebApp/appsettings.Example.json new file mode 100644 index 0000000..299b417 --- /dev/null +++ b/DbFirst.BlazorWebApp/appsettings.Example.json @@ -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" + } +} \ No newline at end of file diff --git a/DbFirst.BlazorWebApp/appsettings.json b/DbFirst.BlazorWebApp/appsettings.json index 7779dac..175eb90 100644 --- a/DbFirst.BlazorWebApp/appsettings.json +++ b/DbFirst.BlazorWebApp/appsettings.json @@ -1,11 +1,25 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } +"Logging": { + "LogLevel": { + "Default": "Information", + "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/", - "DataApiBaseUrl": "https://localhost:7204/", - "AllowedHosts": "*" + "DbFirstService": { + "BaseUrl": null, + "GetData": "dbfirst/data", + "UpdateData": "dbfirst/update" + } }