using System.Data; using GB5Shared.GOP.Qualifier; using System.Reflection; using GB5Shared.Addon; using GB5Shared.DaprCache; using GB5Shared.DTO.Framework.CommonConfig; using GB5Shared.EntityHandler; using GB5Shared.EventLogPublish; using GB5Shared.GB5Library.Qualifier; using GB5Shared.GenerateAutoNumber; using GB5Shared.GOP.ExecuteAsync; using GB5Shared.Hosting; using GB5Shared.PubSub.OutBox; using GB5Shared.WorkFlow.WorkFlowEngine; using GB5Shared.WorkFlow.WorkFlowRunTime; using Microsoft.Data.SqlClient; using Npgsql; using PERMBLL.Interfaces; using PERMSL.Hubs; using PERMSL.Infrastructure; using static GB5Shared.DTO.Framework.Enum.FrameworkEnumDTO; namespace PERMSL; public class PERMModule : IModule { public void Register(IServiceCollection services, IConfiguration configuration) { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); services.AddSignalR(options => { options.EnableDetailedErrors = true; options.MaximumReceiveMessageSize = 32 * 1024; options.ClientTimeoutInterval = TimeSpan.FromSeconds(60); options.KeepAliveInterval = TimeSpan.FromSeconds(15); }); services.AddHttpClient(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(typeof(BaseEntityAppService<>), typeof(BaseEntityAppService<>)); services.AddScoped(); services.AddGB5QualifierEngine(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); var gb5Config = configuration.GetSection("Gb5SystemDTO").Get()!; var activeDbType = (DatabaseType)gb5Config.DataBaseType; services.AddSingleton(new DatabaseTypeConfig(activeDbType)); services.AddScoped(_ => { 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.") }; }); var permBLLAssembly = Assembly.Load("PERMBLL"); var permDALAssembly = Assembly.Load("PERMDAL"); services.Scan(scan => scan .FromAssemblies(permBLLAssembly, permDALAssembly) .AddClasses(c => c.Where(t => !t.IsAbstract && !t.IsInterface && t.GetMethod("$") == null)) .AsImplementedInterfaces() .WithScopedLifetime()); } public void MapEndpoints(WebApplication app) { app.MapHub("/hubs/perm"); } }