IdentityDbContextDesignTimeFactory.cs 1.1 KB

1234567891011121314151617181920212223242526
  1. using Microsoft.EntityFrameworkCore;
  2. using Microsoft.EntityFrameworkCore.Design;
  3. using Microsoft.EntityFrameworkCore.Diagnostics;
  4. namespace Infrastructure.Persistence;
  5. /// <summary>
  6. /// Design-time DbContext factory for IdentityDbContext.
  7. /// See <see cref="AppDbContextDesignTimeFactory"/> for rationale.
  8. /// </summary>
  9. public sealed class IdentityDbContextDesignTimeFactory : IDesignTimeDbContextFactory<IdentityDbContext>
  10. {
  11. public IdentityDbContext CreateDbContext(string[] args)
  12. {
  13. var conn = Environment.GetEnvironmentVariable("ConnectionStrings__IdentityDbContextConnection")
  14. ?? Environment.GetEnvironmentVariable("ConnectionStrings__DefaultConnection")
  15. ?? "Server=.\\SQLEXPRESS;Database=dpot;Trusted_Connection=True;TrustServerCertificate=True;MultipleActiveResultSets=true";
  16. var options = new DbContextOptionsBuilder<IdentityDbContext>()
  17. .UseSqlServer(conn)
  18. .ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning))
  19. .Options;
  20. return new IdentityDbContext(options);
  21. }
  22. }