Files
EnvelopeGenerator/EnvelopeGenerator.Infrastructure/EGDbContextFactory.cs
TekH 7495e062a9 Remove EnvelopeSigningType enum and update envelope logic
Removed EnvelopeSigningType enum and related normalization logic. Added a ReadOnly property to Envelope that uses EnvelopeTypeId to determine read-only status. Envelope type handling now relies on EnvelopeTypeId (int?) instead of the enum.
2026-01-19 16:50:02 +01:00

48 lines
1.7 KiB
C#

#if NET
using EnvelopeGenerator.Application.Common.Configurations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.Infrastructure
{
public class EGDbContextFactory : IDesignTimeDbContextFactory<EGDbContext>
{
public EGDbContext CreateDbContext(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.migration.json")
.Build();
// create DbContextOptions
var optionsBuilder = new DbContextOptionsBuilder<EGDbContext>();
optionsBuilder.UseSqlServer(config.GetConnectionString("Default"));
// create DbTriggerParams
var triggerLists = config.GetSection("DbTriggerParams").Get<Dictionary<string, List<string>>>();
var dbTriggerParams = new DbTriggerParams();
if (triggerLists is not null)
foreach (var triggerList in triggerLists)
{
if (triggerList.Value.Count == 0)
continue; // Skip empty trigger lists
var tableName = triggerList.Key;
dbTriggerParams[tableName] = new List<string>();
foreach (var trigger in triggerList.Value)
{
dbTriggerParams[tableName].Add(trigger);
}
}
var dbContext = new EGDbContext(optionsBuilder.Options, Options.Create(dbTriggerParams));
dbContext.IsMigration = true;
return dbContext;
}
}
}
#endif