Open Closed

Database seed production only IHostingEnvironment #7144

digitalcontrol created

I want to seed database on app start only in production mode. What is the best way to do that? I injected IHostingEnvironment in RIMIKSXEntityFrameworkCoreModule and added code

public override void Initialize() { IocManager.RegisterAssemblyByConvention(typeof(RIMIKSXEntityFrameworkCoreModule).GetAssembly());

// ignore seeding in development
if (_env.IsDevelopment())
    SkipDbSeed = true;


and it works fine. But now Migrator project and Unit tests don't work, because of that dependency. This is the error message: Can't create component 'RIMIKSX.EntityFrameworkCore.RIMIKSXEntityFrameworkCoreModule' as it has dependencies to be satisfied.

1 Answer(s)
  • 0
    maliming created

    You can try use the Substitute class library mock IHostingEnvironment.