使用Web Api 2的Autofac,我可以将当前的http请求实例绑定到某个c#类。
如何在没有 autofac 的情况下使用 asp.net 核心执行此操作,只需使用
IServiceCollection services
您可以注册IHttpContextAccessor
并将其注入到您的服务中
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
然后,您可以通过httpContextAccessor.HttpContext
访问HttpContext。