using EgwCoreLib.Lux.Data.Services; using EgwMultiEngineManager; using Lux.API.Services; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.OpenApi.Models; using NLog; using NLog.Web; using StackExchange.Redis; using System.Reflection; using System.Runtime.Intrinsics.X86; var builder = WebApplication.CreateBuilder(args); var logger = LogManager.Setup() .LoadConfigurationFromAppSettings() .GetCurrentClassLogger(); var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version?.ToString(); ConfigurationManager configuration = builder.Configuration; logger.Info($"Program.cs: startup | v.{assemblyVersion}"); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); //builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "EgaWare's Lux API", Version = $"v1 | {assemblyVersion}", Description = $"API documentation for v1 | AssemblyVersion {assemblyVersion}" }); }); // costruzione connectionMultiplexer redis... string connStr = configuration.GetConnectionString("Redis") ?? "localhost"; ConnectionMultiplexer redisConn = ConnectionMultiplexer.Connect(connStr); // registro connMultiplexer REDIS builder.Services.AddSingleton(redisConn); // registro wrapper servizi REDIS builder.Services.AddSingleton(); builder.Services.AddSingleton(); // altri servizi! builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddHostedService(); var app = builder.Build(); // aggiunt base URL x routing corretto string baseUrl = configuration.GetValue("ServerConf:BaseUrl") ?? ""; app.UsePathBase(baseUrl); logger.Info($"BaseUrl: {baseUrl}"); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment() || app.Environment.IsStaging()) { app.UseSwagger(); //app.UseSwaggerUI(); app.UseSwaggerUI(c => { c.SwaggerEndpoint($"{baseUrl}swagger/v1/swagger.json", "EgalWare's Lux API v1"); }); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); // inserisco evento in chiusura x fermare i thread di calcolo sottostanti: // https://shazwazza.com/post/aspnet-core-application-shutdown-events/ // https://dotnetblog.asphostportal.com/how-to-handle-application-shutdown-in-asp-net-core/ app.Lifetime.ApplicationStopping.Register(() => { #if false if (myExecProcessManager != null) { myExecProcessManager.StopExecutionThread(); } #endif }); // avvio app app.Run();