Add conditional Windows Service & Kestrel config support

The app now checks configuration values to optionally run as a Windows Service ("UseWindowsService") and/or apply custom Kestrel server settings from the "Kestrel" config section ("UseKestrelConfig"). These changes improve deployment flexibility.
This commit is contained in:
2026-04-09 14:20:04 +02:00
parent 2458d0c07a
commit bda4f3dbef

View File

@@ -9,7 +9,21 @@ using System.Globalization;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
#region Kestrel & Windows Service Configuration
if (builder.Configuration.GetValue<bool>("UseWindowsService"))
{
builder.Host.UseWindowsService();
}
if (builder.Configuration.GetValue<bool>("UseKestrelConfig"))
{
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
{
var kestrelSection = context.Configuration.GetSection("Kestrel");
serverOptions.Configure(kestrelSection);
});
}
#endregion
var config = builder.Configuration;
var connStr = config.GetConnectionString("Default") ??
@@ -76,4 +90,4 @@ app.UseAuthorization();
app.MapControllers();
app.Run();
app.Run();