using Microsoft.AspNetCore.Components.Authorization; using Microsoft.Extensions.DependencyInjection; using ScadaLink.CentralUI.Auth; using ScadaLink.CentralUI.Components.Shared; using ScadaLink.CentralUI.ScriptAnalysis; using ScadaLink.CentralUI.Services; using ScadaLink.HealthMonitoring; namespace ScadaLink.CentralUI; public static class ServiceCollectionExtensions { public static IServiceCollection AddCentralUI(this IServiceCollection services) { services.AddRazorComponents() .AddInteractiveServerComponents(); services.AddHttpContextAccessor(); services.AddScoped(); services.AddCascadingAuthenticationState(); // Resolves the current user's permitted site set from their SiteId claims // so Deployment/Monitoring pages can enforce site scoping (CentralUI-002). services.AddScoped(); // Centralised dialog service: pages inject IDialogService and a single // in MainLayout renders the active dialog. See // Components/Shared/IDialogService.cs. services.AddScoped(); // Audit Log (#23 M7-T3): CentralUI facade over IAuditLogRepository so the // results grid can be tested with a stubbed query source. // // Registered with an explicit factory so the IServiceScopeFactory ctor is // always chosen — AuditLogQueryService has a second (test-seam) ctor that // takes IAuditLogRepository directly, and both are constructor-resolvable, // so default activation would be ambiguous. The scope-factory ctor opens a // fresh DbContext per query, which is what keeps the page's auto-load from // racing AuditFilterBar's site enumeration on the shared scoped context. services.AddScoped(sp => new AuditLogQueryService( sp.GetRequiredService(), sp.GetRequiredService())); // Audit Log (#23 M7-T14 / Bundle F): server-side streaming CSV export. // Backs the Audit Log page's Export button via GET /api/centralui/audit/export. services.AddScoped(); // Roslyn-backed C# analysis for the Monaco script editor. // Scoped because SharedScriptCatalog wraps a scoped service. services.AddMemoryCache(o => o.SizeLimit = 200); services.AddScoped(); services.AddScoped(); return services; } }