/// <summary> /// Add a pessimistic lock to the database context /// </summary> /// <param name="correlationId"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task Lock(Guid correlationId, CancellationToken cancellationToken) { if (_lock != null) { throw new InvalidOperationException("The database context is already locked"); } var sagaLock = new SagaLock(_database, _options, correlationId); _lock = await sagaLock.Lock(cancellationToken).ConfigureAwait(false); }
Task <IAsyncDisposable> Lock(TSaga instance, CancellationToken cancellationToken) { var sagaLock = new SagaLock(_database, _options, instance.CorrelationId); return(sagaLock.Lock(cancellationToken)); }