From bda4f3dbef7dea4f439b27eea55db3208a2ea1b1 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 9 Apr 2026 14:20:04 +0200 Subject: [PATCH] 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. --- EnvelopeGenerator.ServiceHost/Program.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/EnvelopeGenerator.ServiceHost/Program.cs b/EnvelopeGenerator.ServiceHost/Program.cs index 753fc5f9..9fe2688e 100644 --- a/EnvelopeGenerator.ServiceHost/Program.cs +++ b/EnvelopeGenerator.ServiceHost/Program.cs @@ -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("UseWindowsService")) +{ + builder.Host.UseWindowsService(); +} + +if (builder.Configuration.GetValue("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(); \ No newline at end of file