using FastEndpoints; using FastEndpoints.Swagger; using GB5Shared.GOP.Qualifier; using GB5Shared.Addon; using GB5Shared.Connection; using GB5Shared.Telemetry; using GB5Shared.DateConverter; using static GB5Shared.DateConverter.GB5JsonOptions; using GB5Shared.DTO.Framework.CommonConfig; using GB5Shared.EntityHandler; using GB5Shared.EventLogPublish; using GB5Shared.GB5CommonFunction; using GB5Shared.GB5Library.Qualifier; using GB5Shared.GenerateAutoNumber; using GB5Shared.GOP.ExecuteAsync; using GB5Shared.PickListGenerator; using GB5Shared.PubSub.OutBox; using GB5Shared.QueryExecutor; using GB5Shared.Validation; using GB5Shared.WorkFlow.WorkFlowEngine; using GB5Shared.WorkFlow.WorkFlowRunTime; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Caching.Hybrid; using OpenTelemetry; using OpenTelemetry.Trace; using System.Data; using System.Reflection; using System.Text; using Microsoft.Data.SqlClient; using OpenTelemetry.Resources; using OpenTelemetry.Metrics; using Npgsql; using static GB5Shared.DTO.Framework.Enum.FrameworkEnumDTO; using CMGMBLL.Interfaces; var builder = WebApplication.CreateBuilder(args); Console.OutputEncoding = Encoding.UTF8; var appPort = builder.Configuration.GetValue("AppPort"); builder.WebHost.UseUrls($"http://0.0.0.0:{appPort}"); builder.Services.AddDaprClient(); builder.Services.AddControllers() .AddDapr() .AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = null; options.JsonSerializerOptions.DictionaryKeyPolicy = null; options.JsonSerializerOptions.AddGB5Converters(); }); builder.Services.Configure(options => { options.SuppressModelStateInvalidFilter = true; }); 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.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddHttpClient(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(typeof(BaseEntityAppService<>), typeof(BaseEntityAppService<>)); builder.Services.AddScoped(); builder.Services.AddGB5QualifierEngine(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.Configure( builder.Configuration.GetSection("Gb5SystemDTO")); var gb5Config = builder.Configuration .GetSection("Gb5SystemDTO") .Get(); var activeDbType = (DatabaseType)gb5Config!.DataBaseType; builder.Services.AddSingleton(new DatabaseTypeConfig(activeDbType)); builder.Services.Configure(options => { options.AllowSynchronousIO = true; }); builder.Services.AddGB5Telemetry(builder.Configuration, "GB5-CMGM"); var cmgmBLLAssembly = Assembly.Load("CMGMBLL"); var cmgmDALAssembly = Assembly.Load("CMGMDAL"); var permDALAssembly = Assembly.Load("PERMDAL"); var skillDALAssembly = Assembly.Load("SkillManagementDAL"); builder.Services.Scan(scan => scan .FromAssemblies(cmgmBLLAssembly, cmgmDALAssembly, permDALAssembly, skillDALAssembly) .AddClasses(c => c.Where(t => !t.IsAbstract && !t.IsInterface && t.GetMethod("$") == null)) .AsImplementedInterfaces() .WithScopedLifetime()); builder.Services.AddScoped(sp => { var connStr = gb5Config.ActiveConnectionString; return activeDbType switch { DatabaseType.SQL => (IDbConnection)new SqlConnection(connStr), DatabaseType.POSTGRE => (IDbConnection)new NpgsqlConnection(connStr), _ => throw new NotSupportedException($"DataBaseType '{gb5Config.DataBaseType}' not supported.") }; }); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); builder.Services.AddFastEndpoints(); builder.Services.SwaggerDocument(o => { o.DocumentSettings = s => { s.Title = "GB5 Competency Management API"; s.Version = "v1"; s.Description = "GB5 Competency Management (CMGM) Microservice"; }; }); var app = builder.Build(); app.UseCloudEvents(); app.UseMiddleware(); app.UseMiddleware(); app.UseFastEndpoints(c => { c.Serializer.Options.PropertyNamingPolicy = null; c.Serializer.Options.DictionaryKeyPolicy = null; c.Serializer.Options.AddGB5Converters(); }); app.MapControllers(); app.MapSubscribeHandler(); app.UseAuthorization(); app.UseOpenApi(); app.UseSwaggerUi(o => { o.Path = "/GB5Documentation"; o.DocumentPath = "/swagger/{documentName}/swagger.json"; o.TransformToExternalPath = (internalUiRoute, _) => "/cmgm" + internalUiRoute; }); app.MapGet("/", () => "Hello from GB5 Competency Management Service (.NET 9)"); app.Run();