-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding an AsyncLocalTransactionContextPropagator.
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |