[CHANGE] Moved to appsettings settings

This commit is contained in:
max
2025-08-18 01:08:11 +02:00
parent f784000393
commit 4dc3ffda36
6 changed files with 52 additions and 3 deletions

View File

@@ -1,12 +1,29 @@
using DotBased.Logging;
using DotBased.Logging.MEL;
using DotBased.Logging.Serilog;
using Manager.App.Models.Settings;
using Serilog;
namespace Manager.App;
public static class DependencyInjection
{
public static void SetupSettings(this WebApplicationBuilder builder)
{
builder.Services.AddOptions<LibrarySettings>()
.Bind(builder.Configuration.GetSection("Library"))
.ValidateDataAnnotations()
.PostConfigure(settings =>
{
settings.Path = settings.Path.Replace("{workdir}", Environment.CurrentDirectory, StringComparison.InvariantCultureIgnoreCase);
})
.ValidateOnStart();
builder.Services.AddOptions<DownloadSettings>()
.Bind(builder.Configuration.GetSection("Downloads"))
.ValidateDataAnnotations()
.ValidateOnStart();
}
public static void SetupLogging(this WebApplicationBuilder builder)
{
var isDevelopment = builder.Environment.IsDevelopment();

View File

@@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.App.Models.Settings;
public class DownloadSettings
{
[ConfigurationKeyName("MaxConcurrentDownloads")]
[Range(-1, 20)]
public int MaxConcurrentDownloads { get; set; }
}

View File

@@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.App.Models.Settings;
public class LibrarySettings
{
[ConfigurationKeyName("Path")]
[Required]
public required string Path { get; set; }
}

View File

@@ -8,10 +8,10 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.SetupLogging();
/* App setup */
builder.SetupLogging();
builder.SetupSettings();
/* MudBlazor */
builder.Services.AddMudServices();

View File

@@ -16,5 +16,11 @@
"Default": "Trace",
"Microsoft.AspNetCore": "Debug"
}
},
"Library": {
"Path": "{workdir}/"
},
"Downloads": {
"MaxConcurrentDownloads": 5
}
}

View File

@@ -17,5 +17,11 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Library": {
"Path": "{workdir}/Library"
},
"Downloads": {
"MaxConcurrentDownloads": 5
}
}