コード例 #1
0
 public UnitOfWorkMemoryDatabaseProvider(
     IUnitOfWorkManager unitOfWorkManager,
     IConnectionStringResolver connectionStringResolver,
     TMemoryDbContext dbContext,
     MemoryDatabaseManager memoryDatabaseManager)
 {
     _unitOfWorkManager        = unitOfWorkManager;
     _connectionStringResolver = connectionStringResolver;
     DbContext = dbContext;
     _memoryDatabaseManager = memoryDatabaseManager;
 }
コード例 #2
0
        public IMemoryDatabase GetDatabase()
        {
            var unitOfWork = _unitOfWorkManager.Current;

            if (unitOfWork == null)
            {
                throw new AbpException($"A {nameof(IMemoryDatabase)} instance can only be created inside a unit of work!");
            }

            var connectionString = _connectionStringResolver.Resolve <TMemoryDbContext>();
            var dbContextKey     = $"{typeof(TMemoryDbContext).FullName}_{connectionString}";

            var databaseApi = unitOfWork.GetOrAddDatabaseApi(
                dbContextKey,
                () => new MemoryDbDatabaseApi(
                    MemoryDatabaseManager.Get(connectionString)
                    ));

            return(((MemoryDbDatabaseApi)databaseApi).Database);
        }