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);
        }
예제 #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
예제 #3
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             context.Dispose();
         }
     }
     this.disposed = true;
 }
예제 #4
0
        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;
            }
        }
예제 #5
0
 public void Dispose()
 {
     _context?.Dispose();
 }
예제 #6
0
 public void Dispose()
 {
     _context.Dispose();
     _context = null;
 }