public override void PreInitialize() { Configuration.ReplaceService(typeof(IConnectionStringResolver), () => { IocManager.IocContainer.Register( Component.For <IConnectionStringResolver, IDbPerTenantConnectionStringResolver>() .ImplementedBy <DbPerTenantConnectionStringResolver>() .LifestyleTransient() ); }); //使用自定义的实体查找类代替默认的 Configuration.ReplaceService <IDbContextEntityFinder, MasterDbContextEntityFinder>(); Configuration.Modules.AbpEfCore().AddDbContext <MasterDbContext>(options => { //此行会减缓执行速度,仅供调试使用 //options.DbContextOptions.UseLoggerFactory(Mlogger); if (options.ExistingConnection != null) { DbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { DbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); }
public MasterDbContext CreateDbContext(string[] args) { var builder = new DbContextOptionsBuilder <MasterDbContext>(); var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder()); DbContextOptionsConfigurer.Configure( builder, configuration.GetConnectionString(MasterConsts.ConnectionStringName) ); return(new MasterDbContext(builder.Options)); }