Skip to content

Commit

Permalink
Adding an AsyncLocalTransactionContextPropagator.
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
  • Loading branch information
askpt committed Dec 19, 2024
1 parent d9ed730 commit 9f75a44
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/OpenFeature/AsyncLocalTransactionContextPropagator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Threading;
using OpenFeature.Model;

namespace OpenFeature;

/// <summary>
/// It is a no-op implementation of <see cref="ITransactionContextPropagator"/>
/// It uses the <see cref="AsyncLocal{T}"/> to store the transaction context.
/// </summary>
public sealed class AsyncLocalTransactionContextPropagator : ITransactionContextPropagator
{
private readonly AsyncLocal<EvaluationContext> _transactionContext = new();

/// <inheritdoc />
public EvaluationContext GetTransactionContext()
{
return this._transactionContext.Value ?? EvaluationContext.Empty;
}

/// <inheritdoc />
public void SetTransactionContext(EvaluationContext evaluationContext)
{
this._transactionContext.Value = evaluationContext;
}
}

0 comments on commit 9f75a44

Please sign in to comment.