Class DocumentLease<T, TKey>
Lease over multiple locked documents. Per-document commit decisions are staged via
MarkForUpdate, MarkForDelete(TKey), or MarkRelease(TKey),
and applied sequentially on CommitAsync(bool, CancellationToken). Disposal without commit releases all
not-yet-marked locks.
public class DocumentLease<T, TKey> : IAsyncDisposable, IDisposable where T : LockableEntityBase<TKey>
Type Parameters
TTKey
- Inheritance
-
DocumentLease<T, TKey>
- Implements
- Derived
- Inherited Members
Properties
Documents
The locked documents at the time of acquisition, in lock-acquisition order.
public IReadOnlyList<T> Documents { get; }
Property Value
Methods
CommitAsync(bool, CancellationToken)
Apply all staged decisions in the order they were marked. Any not-yet-marked locks are released unchanged.
public Task<DocumentLeaseCommitSummary<TKey>> CommitAsync(bool transactional = false, CancellationToken cancellationToken = default)
Parameters
transactionalboolWhen
false(default), each decision is applied sequentially and per-decision failures are collected into Failures rather than thrown — remaining decisions still attempt to apply. Whentrue, the entire commit pass runs inside a transaction so all decisions land atomically (or none do). If the lease was created with a bound session (caller is already inside an outer transaction) the bound session is reused. Any decision-time failure aborts the transaction and rethrows; on abort no decisions land and the locks remain held on the documents.cancellationTokenCancellationTokenCancels between operations. Honored before each decision is applied.
Returns
- Task<DocumentLeaseCommitSummary<TKey>>
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Releases any locks that have not been released by a prior CommitAsync(bool, CancellationToken).
public ValueTask DisposeAsync()
Returns
MarkForDelete(TKey)
Stage a delete for the document with the given id.
public void MarkForDelete(TKey id)
Parameters
idTKey
MarkForUpdate(T)
Stage an update for the document whose Id matches updated.Id.
public void MarkForUpdate(T updated)
Parameters
updatedT
MarkForUpdate(TKey, T)
Stage an update for the document with the given id, replacing it with updated.
public void MarkForUpdate(TKey id, T updated)
Parameters
idTKeyupdatedT
MarkRelease(TKey)
Stage an explicit release-unchanged for the document with the given id.
Equivalent to leaving the document unmarked at commit time.
public void MarkRelease(TKey id)
Parameters
idTKey