// The bulk of the clean-up code is implemented in Dispose(bool) protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { // free other managed objects that implement // IDisposable only try { if (_objectContext != null) { if (_objectContext.Connection.State == ConnectionState.Open) { _objectContext.Connection.Close(); } _objectContext.Dispose(); _objectContext = null; } if (_dbContext != null) { _dbContext.Dispose(); _dbContext = null; } } catch (ObjectDisposedException) { // do nothing, the objectContext has already been disposed } if (_repositories != null) { _repositories = null; } } _disposed = true; } }
public Repository(IObservableDbContextAsync context, IUnitOfWorkAsync unitOfWork) { _dbContext = context; _unitOfWork = unitOfWork; // Temporarily for FakeDbContext, Unit Test and Fakes var dbContext = context as DbContext; if (dbContext != null) { _dbSet = dbContext.Set <TEntity>(); } else { var fakeContext = context as FakeDbContext; if (fakeContext != null) { _dbSet = fakeContext.Set <TEntity>(); } } }
public UnitOfWork(IObservableDbContextAsync dbContext) { _dbContext = dbContext; _repositories = new Dictionary <string, dynamic>(); }