Table of Contents

Class DocumentLease<T, TKey>

Namespace
Tharga.MongoDB.Lockable
Assembly
Tharga.MongoDB.dll

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

T
TKey
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

IReadOnlyList<T>

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

transactional bool

When false (default), each decision is applied sequentially and per-decision failures are collected into Failures rather than thrown — remaining decisions still attempt to apply. When true, 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.

cancellationToken CancellationToken

Cancels 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

ValueTask

MarkForDelete(TKey)

Stage a delete for the document with the given id.

public void MarkForDelete(TKey id)

Parameters

id TKey

MarkForUpdate(T)

Stage an update for the document whose Id matches updated.Id.

public void MarkForUpdate(T updated)

Parameters

updated T

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

id TKey
updated T

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

id TKey