using Microsoft.AspNetCore.DataProtection; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using ScadaLink.Commons.Interfaces.Repositories; using ScadaLink.Commons.Interfaces.Services; using ScadaLink.ConfigurationDatabase.Repositories; using ScadaLink.ConfigurationDatabase.Services; namespace ScadaLink.ConfigurationDatabase; public static class ServiceCollectionExtensions { /// /// Registers the ScadaLinkDbContext with the provided SQL Server connection string. /// public static IServiceCollection AddConfigurationDatabase(this IServiceCollection services, string connectionString) { services.AddDbContext(options => options.UseSqlServer(connectionString) .ConfigureWarnings(w => w.Ignore( Microsoft.EntityFrameworkCore.Diagnostics.RelationalEventId.PendingModelChangesWarning))); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddDataProtection() .PersistKeysToDbContext(); return services; } /// /// Registers the ScadaLinkDbContext with no connection string (for backward compatibility / Phase 0 stubs). /// This overload is a no-op placeholder; callers should migrate to the overload that accepts a connection string. /// public static IServiceCollection AddConfigurationDatabase(this IServiceCollection services) { // Retained for backward compatibility during migration. // Site nodes do not use the configuration database, so this is intentionally a no-op. return services; } }