using System.Reflection; using System.Text; using FastEndpoints; using FastEndpoints.Swagger; using GB5Shared.Connection; using GB5Shared.Telemetry; using GB5Shared.DateConverter; using static GB5Shared.DateConverter.GB5JsonOptions; using GB5Shared.DTO.Framework.CommonConfig; using GB5Shared.GenerateAutoNumber; using GB5Shared.QueryExecutor; using GB5Shared.Validation; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.ResponseCompression; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Caching.Hybrid; using OpenTelemetry; Console.OutputEncoding = Encoding.UTF8; var builder = WebApplication.CreateBuilder(args); // ── Port from config — change "AppPort" in appsettings.json to use any port ── var appPort = builder.Configuration.GetValue("AppPort"); builder.WebHost.UseUrls($"http://0.0.0.0:{appPort}"); builder.Services.AddDaprClient(); builder.Services.AddHttpClient(); builder.Services.AddControllers() .AddDapr() .AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = null; options.JsonSerializerOptions.DictionaryKeyPolicy = null; options.JsonSerializerOptions.AddGB5Converters(); }); builder.Services.ConfigureHttpJsonOptions(options => { options.SerializerOptions.PropertyNamingPolicy = null; options.SerializerOptions.DictionaryKeyPolicy = null; options.SerializerOptions.AddGB5Converters(); }); #pragma warning disable EXTEXP0018 builder.Services.AddHybridCache(options => { options.DefaultEntryOptions = new HybridCacheEntryOptions(); options.DisableCompression = false; }); #pragma warning restore EXTEXP0018 builder.Services.AddMemoryCache(); builder.Services.AddDistributedMemoryCache(); builder.Services.AddHttpContextAccessor(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.Configure(options => { options.AllowSynchronousIO = true; }); builder.Services.AddResponseCompression(o => { o.EnableForHttps = true; o.Providers.Add(); }); builder.Services.AddGB5Telemetry(builder.Configuration, "GB5-IDMS"); builder.Services.Configure(builder.Configuration.GetSection("Gb5SystemDTO")); // Assembly scan — auto-registers all BLL and DAL implementations var idmsBllAssembly = Assembly.Load("IDMSBLL"); var idmsDalAssembly = Assembly.Load("IDMSDAL"); builder.Services.Scan(scan => scan .FromAssemblies(idmsBllAssembly, idmsDalAssembly) .AddClasses(c => c.Where(t => !t.IsAbstract && !t.IsInterface && (t.Namespace == null || !t.Namespace.Contains(".DTO")))) .AsImplementedInterfaces() .WithScopedLifetime()); var endpointAssemblies = new[] { Assembly.Load("IDMSSL"), Assembly.Load("IDMSBLL"), Assembly.Load("IDMSDAL"), Assembly.Load("GB5Shared") }; builder.Services.AddFastEndpoints(o => { o.Assemblies = endpointAssemblies; }); builder.Services.SwaggerDocument(o => { o.DocumentSettings = s => { s.Title = "GB5 IDMS API — Integrated Delivery Management System"; s.Version = "v1"; }; o.EnableJWTBearerAuth = false; o.ShortSchemaNames = true; }); var app = builder.Build(); app.UseForwardedHeaders(); app.UseResponseCompression(); app.UseMiddleware(); app.UseMiddleware(); app.UseFastEndpoints(c => { c.Serializer.Options.PropertyNamingPolicy = null; c.Serializer.Options.DictionaryKeyPolicy = null; c.Serializer.Options.AddGB5Converters(); }); app.UseOpenApi(); app.UseSwaggerUi(o => { o.Path = "/IDMSDocumentation"; o.DocumentPath = "/swagger/{documentName}/swagger.json"; o.TransformToExternalPath = (internalUiRoute, _) => "/idms" + internalUiRoute; }); app.UseCloudEvents(); app.MapSubscribeHandler(); app.MapControllers(); app.MapGet("/", () => "Hello from GB5 IDMS .NET 9 API!"); app.UseAuthorization(); app.Run();