mirror of
https://github.com/AlexMacocian/Net.Sdk.Web.Extensions.git
synced 2026-07-15 13:39:29 +00:00
28 lines
787 B
C#
28 lines
787 B
C#
using Microsoft.CorrelationVector;
|
|
using System.Core.Extensions;
|
|
|
|
namespace AspNetCore.Extensions;
|
|
|
|
public static class HttpContextExtensions
|
|
{
|
|
private const string CorrelationVectorKey = "CorrelationVector";
|
|
|
|
public static void SetCorrelationVector(this HttpContext context, CorrelationVector cv)
|
|
{
|
|
context.ThrowIfNull()
|
|
.Items.Add(CorrelationVectorKey, cv);
|
|
}
|
|
|
|
public static CorrelationVector GetCorrelationVector(this HttpContext context)
|
|
{
|
|
context.ThrowIfNull();
|
|
if (!context.Items.TryGetValue(CorrelationVectorKey, out var cvVal) ||
|
|
cvVal is not CorrelationVector cv)
|
|
{
|
|
throw new InvalidOperationException("Unable to extract API Key from context");
|
|
}
|
|
|
|
return cv;
|
|
}
|
|
}
|