From bdb3863c07bc4f3244ea9918c5e82a5d5d7744aa Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 9 Apr 2026 15:54:38 +0200 Subject: [PATCH] Refactor Kestrel config and add exception middleware Replaced "UseKestrelConfig" with "UseCustomKestrelEndpoints" and renamed the "Kestrel" section to "ServerConfig" in both Program.cs and appsettings.json. Updated Kestrel server configuration to use the new section. Added ExceptionHandlingMiddleware to the pipeline for global exception handling. --- EnvelopeGenerator.ServiceHost/Program.cs | 9 ++++++--- EnvelopeGenerator.ServiceHost/appsettings.json | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/EnvelopeGenerator.ServiceHost/Program.cs b/EnvelopeGenerator.ServiceHost/Program.cs index 9fe2688e..e30fdd12 100644 --- a/EnvelopeGenerator.ServiceHost/Program.cs +++ b/EnvelopeGenerator.ServiceHost/Program.cs @@ -3,6 +3,7 @@ using EnvelopeGenerator.Application; using EnvelopeGenerator.Infrastructure; using EnvelopeGenerator.ServiceHost; using EnvelopeGenerator.ServiceHost.Extensions; +using EnvelopeGenerator.ServiceHost.Middleware; using Microsoft.AspNetCore.Localization; using Microsoft.EntityFrameworkCore; using System.Globalization; @@ -15,12 +16,12 @@ if (builder.Configuration.GetValue("UseWindowsService")) builder.Host.UseWindowsService(); } -if (builder.Configuration.GetValue("UseKestrelConfig")) +if (builder.Configuration.GetValue("UseCustomKestrelEndpoints")) { builder.WebHost.ConfigureKestrel((context, serverOptions) => { - var kestrelSection = context.Configuration.GetSection("Kestrel"); - serverOptions.Configure(kestrelSection); + var serverConfigSection = context.Configuration.GetSection("ServerConfig"); + serverOptions.Configure(serverConfigSection); }); } #endregion @@ -65,6 +66,8 @@ builder.Services.AddSwaggerGen(); var app = builder.Build(); +app.UseMiddleware(); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/EnvelopeGenerator.ServiceHost/appsettings.json b/EnvelopeGenerator.ServiceHost/appsettings.json index 9373f8f9..d64c4a0c 100644 --- a/EnvelopeGenerator.ServiceHost/appsettings.json +++ b/EnvelopeGenerator.ServiceHost/appsettings.json @@ -14,8 +14,8 @@ "Default": "Server=SDD-VMP04-SQL17\\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=dd;Encrypt=false;TrustServerCertificate=True;" }, "UseWindowsService": false, - "UseKestrelConfig": false, - "Kestrel": { + "UseCustomKestrelEndpoints": false, + "ServerConfig": { "Endpoints": { "Http": { "Url": "http://localhost:1111"