如何使用 class bind/register 当前 http 请求的用户
How to bind/register the User of the current http request with a class
使用 Web 的 Autofac Api 2 我可以将当前的 http 请求实例绑定到某个 c# class。
如何在没有 autofac 的情况下使用 asp.net 内核,仅使用
IServiceCollection services
您可以注册 IHttpContextAccessor
并将其注入您的服务
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
然后您可以通过httpContextAccessor.HttpContext
访问HttpContext。
使用 Web 的 Autofac Api 2 我可以将当前的 http 请求实例绑定到某个 c# class。
如何在没有 autofac 的情况下使用 asp.net 内核,仅使用
IServiceCollection services
您可以注册 IHttpContextAccessor
并将其注入您的服务
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
然后您可以通过httpContextAccessor.HttpContext
访问HttpContext。