using ce.autofac.extension;
using Microsoft.AspNetCore.Http;
namespace learun.util
{
///
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.09.11
/// 描 述:上下文上下文帮助类
///
public static class ContextHelper
{
///
/// 获取上下文值
///
/// 键
///
public static object GetItem(string key)
{
var accessor = IocManager.Instance.GetService();
accessor.HttpContext.Items.TryGetValue(key, out object res);
return res;
}
///
/// 设置上下文值
///
/// 键
/// 值
public static void SetItem(string key, string value)
{
var accessor = IocManager.Instance.GetService();
if (accessor.HttpContext.Items.ContainsKey(key))
{
accessor.HttpContext.Items.Remove(key);
}
accessor.HttpContext.Items.Add(key, value);
}
///
/// 移除上下文值
///
///
public static void RemoveItem(string key)
{
var accessor = IocManager.Instance.GetService();
if (accessor.HttpContext.Items.ContainsKey(key))
{
accessor.HttpContext.Items.Remove(key);
}
}
}
}