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