只能是API接口,不能是定是定时任务,定时任务是没有httpContext的
//ioc获取 public Class1(IHttpContextAccessor accessor) { this.httpContext=accessor.HttpContext } //方法中获取 var httpContext = DependencyResolver.GetService<IHttpContextAccessor>().HttpContext; //根据上下文对象获取IOC对象 var class2=DependencyResolver.GetHttpContextRequiredService<Class2>();
2016 © donet5.comApache Licence 2.0