using System.Data; using AdminDAL.CustomCode.Period; using GB5Shared.GOP.Qualifier; using System.Reflection; using GB5Shared.Addon; using GB5Shared.DaprCache; using GB5Shared.EntityHandler; using GB5Shared.EventLogPublish; using GB5Shared.GB5Library.Qualifier; using GB5Shared.GenerateAutoNumber; using GB5Shared.GOP.ExecuteAsync; using GB5Shared.Hosting; using GB5Shared.PickListGenerator; using GB5Shared.PubSub.OutBox; using GB5Shared.WorkFlow.WorkFlowEngine; using GB5Shared.WorkFlow.WorkFlowRunTime; using Microsoft.Data.SqlClient; using Npgsql; using PayRollBLL.SAP.Config; using PayRollBLL.SAPPaySlip.Config; using PayRollDAL.CustomeCode.DailyAttendance; using PayRollDAL.CustomeCode.OULevelSetting; using PayRollSL.Services; using static GB5Shared.DTO.Framework.Enum.FrameworkEnumDTO; using GB5Shared.DTO.Framework.CommonConfig; using PayRollDAL.DTO.Employee; namespace PayRollSL; public class PayRollModule : IModule { public void Register(IServiceCollection services, IConfiguration configuration) { // SAP IT Declaration named HttpClient var sapItDecBaseUrl = configuration["SapItDeclaration:BaseUrl"]; if (!string.IsNullOrWhiteSpace(sapItDecBaseUrl)) { services.AddHttpClient("sapItDeclaration", client => { client.BaseAddress = new Uri(sapItDecBaseUrl); client.DefaultRequestHeaders.Add("Accept", "application/json"); }); } else { services.AddHttpClient("sapItDeclaration"); } // SAP PaySlip named HttpClient var sapPaySlipBaseUrl = configuration["SapPaySlip:BaseUrl"]; if (!string.IsNullOrWhiteSpace(sapPaySlipBaseUrl)) { services.AddHttpClient("sapPaySlip", client => { client.BaseAddress = new Uri(sapPaySlipBaseUrl); client.DefaultRequestHeaders.Add("Accept", "application/json"); }); } else { services.AddHttpClient("sapPaySlip"); } // PayRoll-specific config sections services.Configure(configuration.GetSection("DefaultLanguage")); services.Configure(configuration.GetSection(SapItDeclarationOptions.SectionName)); services.Configure(configuration.GetSection(SapPaySlipOptions.SectionName)); // PayRoll-specific services 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(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddHostedService(); // DB connection factory — SQL Server or PostgreSQL based on appsettings DataBaseType var gb5Config = configuration.GetSection("Gb5SystemDTO").Get() ?? throw new InvalidOperationException("Gb5SystemDTO configuration section is missing."); var activeDbType = (DatabaseType)gb5Config.DataBaseType; services.AddSingleton(new DatabaseTypeConfig(activeDbType)); // Npgsql 6+ strict mode: must be set before any NpgsqlConnection is created AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); 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.") }; }); // Scrutor assembly scan — PayRollBLL + PayRollDAL var payRollBLLAssembly = Assembly.Load("PayRollBLL"); var payRollDALAssembly = Assembly.Load("PayRollDAL"); services.Scan(scan => scan .FromAssemblies(payRollBLLAssembly, payRollDALAssembly) .AddClasses(c => c.Where(t => !t.IsAbstract && !t.IsInterface && t.GetMethod("$") == null)) .AsImplementedInterfaces() .WithScopedLifetime()); // AdminDAL.CustomCode.Period.IPeriodDAL — PerquisitesBLL depends on it, but AdminDAL is a // different module and isn't covered by the scan above. Mirrors Program.cs's standalone // registration of IOULevelSettingDAL/IJobQueueEnqueuer for the same cross-module reason. services.AddScoped(); // GB5Shared.QueueReader/FileImport/FileUpload — EmployeeAttachmentImportBLL/ // EmployeeAttachmentBulkImportJobHandler depend on these. Not covered by the // PayRollBLL/PayRollDAL scan above. IAttachmentDAL/IFileUploadBLL are also registered // host-wide by HRFinanceHost/Program.cs — kept here too since re-registering the same // concrete implementation is harmless and keeps this module runnable standalone. services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); } public void MapEndpoints(WebApplication app) { } }