private bool Release(out IDbContextPool pool, out IDbContextPoolable context) { pool = _contextPool; context = Context; _contextPool = null; Context = null; return(pool != null); }
private void PooledReturn(IDbContextPoolable context) { Interlocked.Decrement(ref _count); Check.DebugAssert(_maxSize == 0 || _pool.Count <= _maxSize, $"_maxSize is {_maxSize}"); context.ClearLease(); context.Dispose(); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual async ValueTask ReturnAsync(IDbContextPoolable context, CancellationToken cancellationToken = default) { if (Interlocked.Increment(ref _count) <= _maxSize) { await context.ResetStateAsync(cancellationToken).ConfigureAwait(false); _pool.Enqueue(context); } else { PooledReturn(context); } }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual void Return(IDbContextPoolable context) { if (Interlocked.Increment(ref _count) <= _maxSize) { context.ResetState(); _pool.Enqueue(context); } else { PooledReturn(context); } }