namespace Bunny.Common.Context; public class BaseContext { // 使用Lazy初始化确保线程安全 public static readonly ThreadLocal UserId = new(); public static readonly ThreadLocal Token = new(); // 用户id相关 public static long? GetUserId() { return UserId.Value; } public static void SetUserId(long? userId) { UserId.Value = userId; } public static string? GetToken() { return Token.Value; } public static void SetToken(string token) { Token.Value = token; } public static void RemoveUser() { Token.Value = null; UserId.Value = null; } }