public AdminDbContext CreateDbContext(string[] args) { var builder = new DbContextOptionsBuilder <AdminDbContext>(); var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true); AdminDbContextConfigurer.Configure(builder, configuration.GetConnectionString(AdminConsts.ConnectionStringName)); return(new AdminDbContext(builder.Options)); }
public override void PreInitialize() { var isUseRowNumber = true; //判断是否注册(单元测试时无法在此时注册) if (IocManager.IsRegistered <IAppConfigurationAccessor>()) { using (var configurationAccessorObj = IocManager.ResolveAsDisposable <IAppConfigurationAccessor>()) { //从配置文件获取是否使用RowNumber进行分页 isUseRowNumber = Convert.ToBoolean(configurationAccessorObj.Object.Configuration["Database:IsUseRowNumber"] ?? "true"); } } if (!SkipDbContextRegistration) { Configuration.Modules.AbpEfCore().AddDbContext <AdminDbContext>(options => { if (options.ExistingConnection != null) { AdminDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { AdminDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString, isUseRowNumber); } }); } //启用实体历史 Configuration.EntityHistory.Selectors.Add( new NamedTypeSelector( "FullAuditedEntities", type => typeof(IFullAudited).IsAssignableFrom(type) ) ); Configuration.EntityHistory.Selectors.Add("AdminEntities", EntityHistoryHelper.TrackedTypes); Configuration.CustomConfigProviders.Add(new EntityHistoryConfigProvider(Configuration)); }