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 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); }