using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; namespace BigRegister.Api.Data; /// /// Factory for short-lived instances. The three stores /// (ApplicationStore/DocumentStore/BriefStore) are static classes — that shape /// predates this persistence layer, which keeps that shape — so they can't take a constructor-injected /// DbContext; each store method opens one here, uses it, and disposes it under its /// own lock instead. /// public static class Db { public static string ConnectionString { get; set; } = "Data Source=bigregister.db"; public static AppDbContext Create() => new(new DbContextOptionsBuilder().UseSqlite(ConnectionString).Options); } /// Lets `dotnet ef migrations add` construct a context at design time /// without booting the full app (no DI registration exists for AppDbContext — /// see Db.Create above for why). Auto-discovered by EF Core's tooling. public sealed class AppDbContextFactory : IDesignTimeDbContextFactory { public AppDbContext CreateDbContext(string[] args) => Db.Create(); }