using CZFW.Core; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Text; namespace CZFW.Framework.Model { public static class CZHttpContext { public static IServiceProvider ServiceProvider; public static Microsoft.AspNetCore.Http.HttpContext Current { get { object factory = ServiceProvider.GetService(typeof(Microsoft.AspNetCore.Http.IHttpContextAccessor)); HttpContext context = ((Microsoft.AspNetCore.Http.HttpContextAccessor)factory).HttpContext; return context; } } public static TType GetObject(this ISession Session, string key) { var jsonStr = Session.GetString(key); var obj = Json.Deserialize(jsonStr); return obj; } public static void SetObject(this ISession Session, string key, TType obj) { var jsonString = obj.ToJson(); Session.SetString(key, jsonString); } private static ILogger logger; public static ILogger Logger { get { if (logger == null) { logger = ServiceProvider.GetService(typeof(ILogger)) as ILogger; } return logger; } } public static void SetLogger(ILogger log) { logger = log; } } }