dotnet-cqrs/Svrnty.CQRS.Events.Abstractions/Correlation/ICorrelationStore.cs

31 lines
1.3 KiB
C#

using System.Threading;
using Svrnty.CQRS.Events.Abstractions.Correlation;
using System.Threading.Tasks;
namespace Svrnty.CQRS.Events.Abstractions.Correlation;
/// <summary>
/// Storage for correlation ID mappings based on business data keys.
/// Allows workflows to be correlated based on business logic rather than explicit ID passing.
/// </summary>
public interface ICorrelationStore
{
/// <summary>
/// Get the correlation ID for a given key.
/// Returns null if no correlation exists for this key.
/// </summary>
/// <param name="keyHash">Hash of the correlation key.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The correlation ID if it exists, null otherwise.</returns>
Task<string?> GetCorrelationIdAsync(string keyHash, CancellationToken cancellationToken = default);
/// <summary>
/// Store a correlation ID for a given key.
/// This creates the mapping between business data and correlation ID.
/// </summary>
/// <param name="keyHash">Hash of the correlation key.</param>
/// <param name="correlationId">The correlation ID to associate with this key.</param>
/// <param name="cancellationToken">Cancellation token.</param>
Task SetCorrelationIdAsync(string keyHash, string correlationId, CancellationToken cancellationToken = default);
}