using System; using System.Threading; namespace Sozsoft.Platform.Identity; public static class PlatformSessionClaimContext { private static readonly AsyncLocal CurrentSessionId = new(); public static string SessionId => CurrentSessionId.Value; public static IDisposable Change(string sessionId) { var previous = CurrentSessionId.Value; CurrentSessionId.Value = sessionId; return new DisposeAction(() => CurrentSessionId.Value = previous); } private sealed class DisposeAction : IDisposable { private readonly Action action; public DisposeAction(Action action) { this.action = action; } public void Dispose() { action(); } } }