using System.Reflection; using GB5Shared.DTO.Framework.Login; using GB5Shared.Hosting; using GB5Shared.ListQuery; using Newtonsoft.Json; namespace PIESL; public class PIEModule : IModule { public void Register(IServiceCollection services, IConfiguration configuration) { services.AddHttpContextAccessor(); services.AddScoped(sp => { var ctx = sp.GetRequiredService().HttpContext; if (ctx != null && ctx.Request.Headers.TryGetValue("Login", out var h)) return JsonConvert.DeserializeObject(h!)!; return new LoginDTO(); }); var bll = Assembly.Load("PIEBLL"); var dal = Assembly.Load("PIEDAL"); services.Scan(scan => scan .FromAssemblies(bll, dal) // Exclude plain DTOs/records — a `record` implicitly implements IEquatable, so without // this filter AsImplementedInterfaces() registers DTOs (e.g. PIEVariantListQuery) as // services and the container later fails trying to activate them via their data constructor. .AddClasses(c => c.Where(t => !t.IsAbstract && !t.IsInterface && (t.Namespace == null || !t.Namespace.Contains(".DTO")))) .AsImplementedInterfaces() .WithScopedLifetime()); services.AddListInfrastructure(dal); } public void MapEndpoints(WebApplication app) { } }