Exemple #1
0
        /// <summary>
        /// Enqueue ab idle connection
        /// </summary>
        /// <param name="dbContext">DB context</param>
        /// <returns>True(Enqueue successfully)/False(Exceeds the max connection and the connection will be disposed)</returns>
        public static bool Enqueue(PgDbContext dbContext)
        {
            lock (enqueueLock)
            {
                if (dbContextQueue.Count < MaxConnections)
                {
                    dbContextQueue.Enqueue(dbContext);
                    Debug.WriteLine($"[DbContextFactory] Enqueue succeed, current stored connections: {dbContextQueue.Count}");
                    return(true);
                }
                else
                {
                    Debug.WriteLine($"[DbContextFactory] Enqueue failed, current stored connections: {dbContextQueue.Count}");

                    if (dbContext != null)
                    {
                        dbContext.Database.CloseConnection();
                        dbContext.Dispose();
                        dbContext = null;
                    }

                    return(false);
                }
            }
        }
Exemple #2
0
 public void Dispose()
 {
     if (_pgContext != null)
     {
         _pgContext.Dispose();
     }
 }
Exemple #3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (disposing)
                {
                    _context.Dispose();
                }
            }

            IsDisposed = true;
        }