public AccountContext GetAccountContext(long?accountNumber) { var accountCtx = new AccountContext(new DbContextOptions <AccountContext>()); if (accountNumber != null) { //TODO: We have to be able to cache this info somehow. var commonAccount = _commonContext.CommonAccounts .Include(ca => ca.Partition) .Where(ca => ca.Number == accountNumber) .AsNoTracking() .SingleOrDefault(); if (commonAccount != null) { // Dispose the one we created at the top of this method. accountCtx.Dispose(); // Create a new context using the partition's connection string. accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(commonAccount.Partition.ConnectionString)); } } return(accountCtx); }
protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { context.Dispose(); } } this.disposed = true; }
private bool disposed = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // TODO: dispose managed state (managed objects). db.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposed = true; } }
public void Dispose() { _context?.Dispose(); }
public void Dispose() { _context.Dispose(); _context = null; }