From 8ea8130c69071b04b560510d3cbd223f020fd7b3 Mon Sep 17 00:00:00 2001 From: Andre Beging Date: Thu, 27 Mar 2025 09:06:43 +0100 Subject: [PATCH] Implement Appsettings --- .../Model/AppSettings.cs | 23 +++++ .../BaseClasses/FsBase.cs | 94 ++++++++++++------- FoodsharingSiegen.Server/Extensions.cs | 5 +- FoodsharingSiegen.Server/Pages/Login.razor | 2 +- .../Properties/launchSettings.json | 2 +- FoodsharingSiegen.Server/Shared/NavMenu.razor | 4 + .../Shared/NavMenu.razor.cs | 19 +++- .../appsettings.Development.json | 9 -- FoodsharingSiegen.Server/appsettings.json | 9 -- .../config/appsettings.json | 3 + 10 files changed, 109 insertions(+), 61 deletions(-) create mode 100644 FoodsharingSiegen.Contracts/Model/AppSettings.cs delete mode 100644 FoodsharingSiegen.Server/appsettings.Development.json delete mode 100644 FoodsharingSiegen.Server/appsettings.json diff --git a/FoodsharingSiegen.Contracts/Model/AppSettings.cs b/FoodsharingSiegen.Contracts/Model/AppSettings.cs new file mode 100644 index 0000000..eef5f12 --- /dev/null +++ b/FoodsharingSiegen.Contracts/Model/AppSettings.cs @@ -0,0 +1,23 @@ +namespace FoodsharingSiegen.Contracts.Model +{ + public class AppSettings + { + #region Public Properties + + /// + /// Gets or sets the title displayed in the sidebar. + /// This property represents the text that appears in the application's sidebar, + /// typically used for informational or navigational purposes. + /// + public string? SidebarTitle { get; set; } + + /// + /// Gets or sets the title of the application. + /// This property holds the display name or title of the application, + /// which may be used for branding purposes in various parts of the UI. + /// + public string? Title { get; set; } = "Foodsharing Musterhausen"; + + #endregion + } +} \ No newline at end of file diff --git a/FoodsharingSiegen.Server/BaseClasses/FsBase.cs b/FoodsharingSiegen.Server/BaseClasses/FsBase.cs index 14f01ba..c7f8462 100644 --- a/FoodsharingSiegen.Server/BaseClasses/FsBase.cs +++ b/FoodsharingSiegen.Server/BaseClasses/FsBase.cs @@ -1,21 +1,73 @@ using Blazorise; using FoodsharingSiegen.Contracts.Entity; +using FoodsharingSiegen.Contracts.Model; using FoodsharingSiegen.Server.Auth; using FoodsharingSiegen.Server.Data.Service; using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Options; namespace FoodsharingSiegen.Server.BaseClasses { /// - /// The fs base class (a. beging, 08.04.2022) + /// The fs base class (a. beging, 08.04.2022) /// - /// + /// public class FsBase : ComponentBase { + #region Dependencies + + [Inject] + private IOptions AppSettingsContainer { get; set; } = null!; + + /// + /// Gets or sets the value of the audit service (ab) + /// + [Inject] + private AuditService AuditService { get; set; } = null!; + + /// + /// Gets or sets the value of the auth service (ab) + /// + [Inject] + protected AuthService AuthService { get; set; } = null!; + + /// + /// Gets or sets the value of the message (ab) + /// + [Inject] + protected IMessageService Message { get; set; } = null!; + + /// + /// Gets or sets the value of the navigation manager (ab) + /// + [Inject] + protected NavigationManager NavigationManager { get; set; } = null!; + + /// + /// Gets or sets the value of the notification (ab) + /// + [Inject] + protected INotificationService Notification { get; set; } = null!; + + #endregion + + #region Protected Properties + + /// Provides application-specific settings used to configure the behavior and display of the application. + /// The AppSettings class encapsulates information such as the application title and other configurable parameters. + protected AppSettings AppSettings => AppSettingsContainer.Value; + + /// + /// Gets the value of the current user (ab) + /// + protected User CurrentUser => AuthService?.User ?? new User(); + + #endregion + #region Override OnInitializedAsync /// - /// Ons the initialized (a. beging, 11.04.2022) + /// Ons the initialized (a. beging, 11.04.2022) /// protected override async Task OnInitializedAsync() { @@ -25,46 +77,16 @@ namespace FoodsharingSiegen.Server.BaseClasses #endregion - #region Dependencies (Injected) + #region Protected Method RefreshState /// - /// Gets or sets the value of the auth service (ab) - /// - [Inject] protected AuthService AuthService { get; set; } = null!; - - /// - /// Gets or sets the value of the audit service (ab) - /// - [Inject] private AuditService AuditService { get; set; } = null!; - - /// - /// Gets or sets the value of the notification (ab) - /// - [Inject] protected INotificationService Notification { get; set; } = null!; - - /// - /// Gets or sets the value of the message (ab) - /// - [Inject] protected IMessageService Message { get; set; } = null!; - - /// - /// Gets or sets the value of the navigation manager (ab) - /// - [Inject] protected NavigationManager NavigationManager { get; set; } = null!; - - #endregion - - /// - /// Refreshes the state (a. beging, 21.05.2022) + /// Refreshes the state (a. beging, 21.05.2022) /// protected async Task RefreshState() { await AuthService?.RefreshState()!; } - /// - /// Gets the value of the current user (ab) - /// - protected User CurrentUser => AuthService?.User ?? new User(); + #endregion } } \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Extensions.cs b/FoodsharingSiegen.Server/Extensions.cs index becd649..cfa8d9a 100644 --- a/FoodsharingSiegen.Server/Extensions.cs +++ b/FoodsharingSiegen.Server/Extensions.cs @@ -1,4 +1,5 @@ -using FoodsharingSiegen.Server.Data; +using FoodsharingSiegen.Contracts.Model; +using FoodsharingSiegen.Server.Data; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration.Json; @@ -52,6 +53,8 @@ namespace FoodsharingSiegen.Server // Add each file to the configuration foreach (var file in configFiles) builder.Configuration.AddJsonFile(file, true, true); } + + builder.Services.Configure(builder.Configuration.GetSection("Settings")); } #endregion diff --git a/FoodsharingSiegen.Server/Pages/Login.razor b/FoodsharingSiegen.Server/Pages/Login.razor index 9c53822..fbccc39 100644 --- a/FoodsharingSiegen.Server/Pages/Login.razor +++ b/FoodsharingSiegen.Server/Pages/Login.razor @@ -6,7 +6,7 @@
-
FS Siegen
+
@AppSettings.Title
diff --git a/FoodsharingSiegen.Server/Properties/launchSettings.json b/FoodsharingSiegen.Server/Properties/launchSettings.json index 434a3c8..fc8f663 100644 --- a/FoodsharingSiegen.Server/Properties/launchSettings.json +++ b/FoodsharingSiegen.Server/Properties/launchSettings.json @@ -12,7 +12,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "http://localhost:8700", + "applicationUrl": "http://localhost:56000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/FoodsharingSiegen.Server/Shared/NavMenu.razor b/FoodsharingSiegen.Server/Shared/NavMenu.razor index d2088db..0cda9b6 100644 --- a/FoodsharingSiegen.Server/Shared/NavMenu.razor +++ b/FoodsharingSiegen.Server/Shared/NavMenu.razor @@ -1,5 +1,9 @@