private static async Task <QueryContext> CreateAsyncCore(IDbConnectionFactory connectionFactory, QueryLoggingContext loggingContext, CancellationToken cancellationToken) { if (SemaphoreLookup.TryGetValue(connectionFactory, out var semaphore)) { await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { loggingContext.Start(); return(new QueryContext(semaphore, loggingContext)); } finally { semaphore.Release(); } } else { loggingContext.Start(); return(new QueryContext(loggingContext)); } }
private QueryContext(AsyncSemaphore semaphore, QueryLoggingContext loggingContext) { _semaphore = semaphore ?? throw new ArgumentNullException(nameof(semaphore)); _loggingContext = loggingContext ?? throw new ArgumentNullException(nameof(loggingContext)); }
public static Task <QueryContext> CreateAsync(IDbConnectionFactory connectionFactory, QueryLoggingContext loggingContext, CancellationToken cancellationToken = default) { if (connectionFactory == null) { throw new ArgumentNullException(nameof(connectionFactory)); } if (loggingContext == null) { throw new ArgumentNullException(nameof(loggingContext)); } return(CreateAsyncCore(connectionFactory, loggingContext, cancellationToken)); }
private QueryContext(QueryLoggingContext loggingContext) { _loggingContext = loggingContext ?? throw new ArgumentNullException(nameof(loggingContext)); }