3 UserInfo
ansonzhang edited this page 2019-10-15 10:58:54 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

获取User info

注意:下边的代码在 netcore 3.0分支的可以下载看看但是同样适用于2.2只不过master分支我没有修改而已。

对应的接口

Blog.Core.Common / HttpContextUser / IUser.cs

Blog.Core.Common / HttpContextUser / AspNetUser.cs

注入服务

services.AddScoped<IUser, AspNetUser>();

使用

构造函数注入:

 private readonly IUser _user;


 public ModuleController(IModuleServices moduleServices, IUser user)
 {
     _moduleServices = moduleServices;
     _user = user;
 }

直接使用:

 module.CreateId = _user.ID;
 module.CreateBy = _user.Name;