Remove EGDbContextFactory and related configuration code
The `EGDbContextFactory` class, which implemented the `IDesignTimeDbContextFactory<EGDbContext>` interface, has been removed. This includes the `CreateDbContext` method, which handled design-time DbContext creation by loading configuration from `appsettings.migration.json`, setting up `DbContextOptions`, and constructing `DbTriggerParams`. Additionally, the `#if NET` preprocessor directive and its corresponding `#endif` have been removed, along with all associated `using` directives. This change suggests that the factory is no longer needed due to a shift in the application's architecture or design-time DbContext handling.
This commit is contained in:
@@ -1,48 +0,0 @@
|
|||||||
#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
|
|
||||||
Reference in New Issue
Block a user