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:
@@ -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();
|
||||
Reference in New Issue
Block a user