using FictionArchive.Service.Shared.Services.Database; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; namespace FictionArchive.Service.Shared.Extensions; public static class DatabaseExtensions { public static IServiceCollection RegisterDbContext( this IServiceCollection services, string connectionString, bool skipInfrastructure = false) where TContext : FictionArchiveDbContext { if (skipInfrastructure) { // For schema export: use in-memory provider to allow EF Core entity discovery services.AddDbContext(options => { options.UseInMemoryDatabase($"SchemaExport_{typeof(TContext).Name}"); }); } else { services.AddDbContext(options => { options.UseNpgsql(connectionString, o => { o.UseNodaTime(); }); }); } return services; } }