mirror of
https://github.com/AlexMacocian/Net.Sdk.Web.Extensions.git
synced 2026-07-18 23:19:30 +00:00
Add project files.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user