Files
components/LiteCharms.Features/Shop/Postgres/ShopDbContextFactory.cs
T
2026-05-13 20:06:24 +02:00

20 lines
699 B
C#

namespace LiteCharms.Features.Shop.Postgres;
public class ShopDbContextFactory : IDesignTimeDbContextFactory<ShopDbContext>
{
public ShopDbContext CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddUserSecrets(typeof(ShopDbContext).Assembly)
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
var optionsBuilder = new DbContextOptionsBuilder<ShopDbContext>();
optionsBuilder.UseNpgsql(configuration.GetConnectionString("PostgresShop"));
return new ShopDbContext(optionsBuilder.Options);
}
}