public DbContext Resolve(DBSelector dbSelector = DBSelector.Master) { DbContext dbContext = null; if (dbSelector.Equals(DBSelector.Master)) { _cacheDbContext.TryGetValue(dbSelector, out dbContext); } //ISSUE:A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe //We do it in temprary, we must optimzie the Framewrok to resolve the multiple thread to call DbContext. else { _slaveCacheDbContext.TryGetValue(Thread.CurrentThread.ManagedThreadId, out dbContext); } if (dbContext != null) { return(dbContext); } var configurer = new AbpDbContextConfiguration <TDbContext>(_dbOptions.DbConnections[dbSelector]); _dbContextConfigurer.Configure(configurer); var actualContext = typeof(TDbContext); dbContext = (DbContext)Activator.CreateInstance(actualContext, configurer.DbContextOptions.Options); if (dbSelector.Equals(DBSelector.Master)) { _cacheDbContext.Add(dbSelector, dbContext); } else { _slaveCacheDbContext.Add(Thread.CurrentThread.ManagedThreadId, dbContext); } return(dbContext); }
public void Configure(AbpDbContextConfiguration <TDbContext> configuration) { Action(configuration); IDbResolve dbResolve = (IDbResolve)serviceProvider.GetService(typeof(IDbResolve)); configuration.DbContextOptions.UseMySQL(dbResolve.GetConnectionString()); }
public DbContext Resolve(DBSelector dbSelector = DBSelector.Master) { DbContext dbContext; CacheDbContext.TryGetValue(dbSelector, out dbContext); if (dbContext != null) { return(dbContext); } var configurer = new AbpDbContextConfiguration <TDbContext>(dbOptions.DbConnections[dbSelector]); dbContextConfigurer.Configure(configurer); var actualContext = typeof(TDbContext); dbContext = (DbContext)Activator.CreateInstance(actualContext, configurer.DbContextOptions.Options); CacheDbContext.Add(dbSelector, dbContext); return(dbContext); }
protected virtual DbContextOptions <TDbContext> CreateOptions <TDbContext>([NotNull] string connectionString, [CanBeNull] DbConnection existingConnection) where TDbContext : DbContext { if (_iocResolver.IsRegistered <IAbpDbContextConfigurer <TDbContext> >()) { var configuration = new AbpDbContextConfiguration <TDbContext>(connectionString, existingConnection); using (var configurer = _iocResolver.ResolveAsDisposable <IAbpDbContextConfigurer <TDbContext> >()) { configurer.Object.Configure(configuration); } return(configuration.DbContextOptions.Options); } if (_iocResolver.IsRegistered <DbContextOptions <TDbContext> >()) { return(_iocResolver.Resolve <DbContextOptions <TDbContext> >()); } throw new AbpException($"Could not resolve DbContextOptions for {typeof(TDbContext).AssemblyQualifiedName}."); }
protected virtual void ReplaceServices <TDbContext>(AbpDbContextConfiguration <TDbContext> configuration) where TDbContext : DbContext { configuration.DbContextOptions.ReplaceService <IEntityMaterializerSource, AbpEntityMaterializerSource>(); }
public static void UseMySQL(this AbpDbContextConfiguration <LeeAbpDbContext> dbContextOptions) { //连接字符串在EF所在Module中设置; dbContextOptions.DbContextOptions.UseMySQL(dbContextOptions.ConnectionString); }
/// <summary> /// 利用此方法从核心数据库中获取各个租户的数据库连接信息; /// </summary> /// <param name="dbContextOptions"></param> /// <param name="dbResolve"></param> public static void UseMySQL(this AbpDbContextConfiguration <LeeAbpDbContext> dbContextOptions, IDbResolve dbResolve) { //连接字符串在EF所在Module中设置; dbContextOptions.DbContextOptions.UseMySQL(dbResolve.GetConnectionString()); }