using System.Reflection; using GB5Shared.Hosting; using GB5Shared.Storage; using GB5Shared.Vault; using Microsoft.Extensions.Hosting; namespace DMSSL; public class DMSModule : IModule { public void Register(IServiceCollection services, IConfiguration configuration) { services.AddGB5Storage(configuration.GetSection("StorageConfiguration")); services.Configure( configuration.GetSection(GB5Shared.Attachment.AttachmentPathSettings.Section)); // IAttachmentUploadService/ITemplateResolutionEngine/IAttachmentPathResolutionService now // live in GB5Shared.Attachment — not covered by the FrameworkBLL/FrameworkDAL scan below. services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddGB5Vault(configuration); services.AddScoped(); services.AddHttpClient("alfresco", client => { client.Timeout = TimeSpan.FromMinutes(10); }); var dmsBLLAssembly = Assembly.Load("DMSBLL"); var dmsDALAssembly = Assembly.Load("DMSDAL"); services.Scan(scan => scan .FromAssemblies(dmsBLLAssembly, dmsDALAssembly) // Canonical filter (mirrors GB5Framework/FrameworkSL/Program.cs's scan): // - IHostedService: hosted services are registered separately with their own lifetime. // - Exception: Exception implements ISerializable/_Exception, so AsImplementedInterfaces() // would otherwise register exception types (e.g. QualifierActivationException) as // services, and DI then fails trying to activate them via their (string) constructor. // - records (detected via the compiler-generated $ method): a record implicitly // implements IEquatable, so without this, DTOs/records get registered as services // and the container fails trying to activate them via their data constructor. // - ReportOrchestration: those services require IReportEndpointRegistry, which is only // wired up via FrameworkSL's AddReportOrchestration() extension (not referenced here). // A blanket scan would register QueryOrchestrator without its registry dependency and // fail DI validation at startup. .AddClasses(c => c.Where(t => !t.IsAbstract && !t.IsInterface && !typeof(IHostedService).IsAssignableFrom(t) && !typeof(Exception).IsAssignableFrom(t) && t.GetMethod("$") == null && (t.Namespace == null || !t.Namespace.Contains(".ReportOrchestration")))) .AsImplementedInterfaces() .WithScopedLifetime()); } public void MapEndpoints(WebApplication app) { } }