winmr-api/Program.cs

49 lines
1.3 KiB
C#
Raw Permalink Normal View History

2025-07-04 00:04:51 +03:00
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright <20> 2024-2025 Gregory Lirent */
2025-07-02 16:06:50 +03:00
2025-06-30 18:15:07 +03:00
using Microsoft.Extensions.Options;
2025-07-02 16:06:50 +03:00
using System.Runtime.Versioning;
2025-06-30 18:15:07 +03:00
using WebmrAPI.Configuration;
using WebmrAPI.Services;
2025-07-02 16:06:50 +03:00
[assembly: SupportedOSPlatform("windows")]
2025-06-30 18:15:07 +03:00
var builder = WebApplication.CreateBuilder(args);
2025-07-03 21:56:20 +03:00
builder.Services.AddWindowsService();
2025-06-30 18:15:07 +03:00
builder.Services.Configure<AppSettings>(builder.Configuration);
builder.Services.AddLogging(config =>
{
config.AddConsole();
config.AddDebug();
});
2025-07-02 16:06:50 +03:00
builder.Services.AddRouting(options =>
{
options.LowercaseUrls = true;
options.LowercaseQueryStrings = true;
});
2025-06-30 18:15:07 +03:00
2025-07-02 16:06:50 +03:00
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
2025-06-30 18:15:07 +03:00
2025-07-02 16:06:50 +03:00
builder.Services.AddSingleton<ProcessMonitor>();
builder.Services.AddHostedService(sp => sp.GetRequiredService<ProcessMonitor>());
2025-06-30 18:15:07 +03:00
2025-07-02 16:06:50 +03:00
// ---------------------------------------------------------------------------------------------------------------------------- \\
2025-06-30 18:15:07 +03:00
2025-07-02 16:06:50 +03:00
var app = builder.Build();
var settings = app.Services.GetRequiredService<IOptions<AppSettings>>().Value;
2025-06-30 18:15:07 +03:00
2025-07-02 16:06:50 +03:00
app.Urls.Add(settings.WebServer.Url);
2025-06-30 18:15:07 +03:00
2025-07-02 16:06:50 +03:00
if (app.Environment.IsDevelopment())
2025-06-30 18:15:07 +03:00
{
2025-07-02 16:06:50 +03:00
app.UseSwagger();
app.UseSwaggerUI();
}
2025-06-30 18:15:07 +03:00
2025-07-02 16:06:50 +03:00
app.MapControllers();
2025-06-30 18:15:07 +03:00
app.Run();