using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Memory; namespace Common.Http { public static class MyHttpContext { //public static IServiceProvider ServiceProvider; private static IHttpContextAccessor m_httpContextAccessor; private static IMemoryCache _cache; static MyHttpContext() { } //public static HttpContext Current1 //{ // get // { // object factory = ServiceProvider.GetService(typeof(Microsoft.AspNetCore.Http.IHttpContextAccessor)); // HttpContext context = ((IHttpContextAccessor)factory).HttpContext; // return context; // } //} public static void Configure(IHttpContextAccessor httpContextAccessor) { m_httpContextAccessor = httpContextAccessor; } public static void Configure(IMemoryCache cache) { _cache = cache; } public static HttpContext Current { get { return m_httpContextAccessor.HttpContext; } } public static IMemoryCache Cache { get { //object factory = ServiceProvider.GetService(typeof(Microsoft.Extensions.Caching.Memory.IMemoryCache)); //MemoryCache context = ((MemoryCache)factory); //return context; return _cache; } } } }