public override void PreInitialize() { Configuration.ReplaceService <IConnectionStringResolver, MyConnectionStringResolver>(); // Configure first DbContext Configuration.Modules.AbpEfCore().AddDbContext <MultipleDbContextEfCoreDemoDbContext>(options => { if (options.ExistingConnection != null) { DbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { DbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); // Configure second DbContext Configuration.Modules.AbpEfCore().AddDbContext <MultipleDbContextEfCoreDemoSecondDbContext>(options => { if (options.ExistingConnection != null) { SecondDbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { SecondDbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); }
public MultipleDbContextEfCoreDemoDbContext CreateDbContext(string[] args) { var builder = new DbContextOptionsBuilder <MultipleDbContextEfCoreDemoDbContext>(); var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder()); DbContextOptionsConfigurer.Configure( builder, configuration.GetConnectionString(MultipleDbContextEfCoreDemoConsts.ConnectionStringName) ); return(new MultipleDbContextEfCoreDemoDbContext(builder.Options)); }