using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using DotNetEnv;
namespace Inventory.Core
{
///
/// This factory is used by the EF Core design-time tools (e.g., for creating migrations).
/// It provides a way to configure and create an instance of the DbContext at design time.
///
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory
{
public InventoryContext CreateDbContext(string[] args)
{
// Load environment variables from .env file up the directory tree
Env.TraversePath().Load();
string connectionString = Env.GetString("DB_CONNECTION_STRING");
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlServer(connectionString);
return new InventoryContext(optionsBuilder.Options);
}
}
}