Table of Contents

Class ModernLockStrategy

Namespace
Compendium.Core.Domain.Primitives
Assembly
Compendium.Core.dll

Modern locking strategy using .NET 9's new Lock type. Provides improved performance over traditional lock statements. Note: For async operations, falls back to SemaphoreSlim due to Lock limitations.

public sealed class ModernLockStrategy : ILockingStrategy, IDisposable
Inheritance
ModernLockStrategy
Implements
Inherited Members

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

ExecuteReadAsync<T>(Func<Task<T>>, CancellationToken)

Executes an async read operation with appropriate locking.

public Task<T> ExecuteReadAsync<T>(Func<Task<T>> operation, CancellationToken cancellationToken = default)

Parameters

operation Func<Task<T>>

The operation to execute.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<T>

The result of the operation.

Type Parameters

T

The return type of the operation.

ExecuteRead<T>(Func<T>)

Executes a read operation with appropriate locking.

public T ExecuteRead<T>(Func<T> operation)

Parameters

operation Func<T>

The operation to execute.

Returns

T

The result of the operation.

Type Parameters

T

The return type of the operation.

ExecuteWrite(Action)

Executes a write operation with appropriate locking.

public void ExecuteWrite(Action operation)

Parameters

operation Action

The operation to execute.

ExecuteWriteAsync(Func<Task>, CancellationToken)

Executes an async write operation with appropriate locking.

public Task ExecuteWriteAsync(Func<Task> operation, CancellationToken cancellationToken = default)

Parameters

operation Func<Task>

The operation to execute.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

A task representing the async operation.