Implement Appsettings

This commit is contained in:
Andre Beging
2025-03-27 09:06:43 +01:00
parent 48db8db8ae
commit 8ea8130c69
10 changed files with 109 additions and 61 deletions

View File

@@ -0,0 +1,23 @@
namespace FoodsharingSiegen.Contracts.Model
{
public class AppSettings
{
#region Public Properties
/// <summary>
/// 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.
/// </summary>
public string? SidebarTitle { get; set; }
/// <summary>
/// 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.
/// </summary>
public string? Title { get; set; } = "Foodsharing Musterhausen";
#endregion
}
}

View File

@@ -1,8 +1,10 @@
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
{
@@ -12,6 +14,56 @@ namespace FoodsharingSiegen.Server.BaseClasses
/// <seealso cref="ComponentBase" />
public class FsBase : ComponentBase
{
#region Dependencies
[Inject]
private IOptions<AppSettings> AppSettingsContainer { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the audit service (ab)
/// </summary>
[Inject]
private AuditService AuditService { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the auth service (ab)
/// </summary>
[Inject]
protected AuthService AuthService { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the message (ab)
/// </summary>
[Inject]
protected IMessageService Message { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the navigation manager (ab)
/// </summary>
[Inject]
protected NavigationManager NavigationManager { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the notification (ab)
/// </summary>
[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;
/// <summary>
/// Gets the value of the current user (ab)
/// </summary>
protected User CurrentUser => AuthService?.User ?? new User();
#endregion
#region Override OnInitializedAsync
/// <summary>
@@ -25,34 +77,7 @@ namespace FoodsharingSiegen.Server.BaseClasses
#endregion
#region Dependencies (Injected)
/// <summary>
/// Gets or sets the value of the auth service (ab)
/// </summary>
[Inject] protected AuthService AuthService { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the audit service (ab)
/// </summary>
[Inject] private AuditService AuditService { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the notification (ab)
/// </summary>
[Inject] protected INotificationService Notification { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the message (ab)
/// </summary>
[Inject] protected IMessageService Message { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the navigation manager (ab)
/// </summary>
[Inject] protected NavigationManager NavigationManager { get; set; } = null!;
#endregion
#region Protected Method RefreshState
/// <summary>
/// Refreshes the state (a. beging, 21.05.2022)
@@ -62,9 +87,6 @@ namespace FoodsharingSiegen.Server.BaseClasses
await AuthService?.RefreshState()!;
}
/// <summary>
/// Gets the value of the current user (ab)
/// </summary>
protected User CurrentUser => AuthService?.User ?? new User();
#endregion
}
}

View File

@@ -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<AppSettings>(builder.Configuration.GetSection("Settings"));
}
#endregion

View File

@@ -6,7 +6,7 @@
<div class="d-flex justify-content-center align-items-center" style="height: 100vh;">
<div class="card" style="width: 100%; max-width: 380px;">
<div class="card-header">FS Siegen</div>
<div class="card-header">@AppSettings.Title</div>
<div class="card-body">
<Validation Validator="ValidationHelper.ValidateMail" @bind-Status="@IsValidMail">
<TextEdit @bind-Text="MailAddress" Role="TextRole.Email" Placeholder="E-Mail" Class="mt-0" KeyUp="TextEdit_KeyUp"></TextEdit>

View File

@@ -12,7 +12,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:8700",
"applicationUrl": "http://localhost:56000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

View File

@@ -1,5 +1,9 @@
<nav class="flex-column">
<div class="nav-logo"></div>
<div class="d-flex px-3 justify-content-center text-center font-weight-bold">
Einarbeitungen<br />
@(AppSettings.SidebarTitle ?? AppSettings.Title)
</div>
<div class="row px-3">
<div class="col">
<div class="nav-item">

View File

@@ -1,6 +1,8 @@
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Model;
using FoodsharingSiegen.Server.Auth;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options;
namespace FoodsharingSiegen.Server.Shared
{
@@ -11,10 +13,11 @@ namespace FoodsharingSiegen.Server.Shared
{
#region Dependencies
/// <summary>
/// Gets or sets the value of the auth service (ab)
/// </summary>
[Inject] protected AuthService AuthService { get; set; } = null!;
[Inject]
private IOptions<AppSettings> AppSettingsContainer { get; set; } = null!;
[Inject]
protected AuthService AuthService { get; set; } = null!;
#endregion
@@ -27,6 +30,14 @@ namespace FoodsharingSiegen.Server.Shared
#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;
#endregion
#region Override OnInitializedAsync
/// <summary>

View File

@@ -1,9 +0,0 @@
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@@ -5,5 +5,8 @@
"Url": "http://+:56000"
}
}
},
"Settings": {
"Title": "Foodsharing Olpe-Wenden"
}
}