【发布时间】:2021-11-17 05:21:06
【问题描述】:
我正在使用 Blazor 和 .NetCore 开发应用程序。
我将 Microsoft 标识用于角色和用户。在 Visual Studio 生成的基础项目中,使用标识的代码默认是构造的。对于项目的目标,我正在使用这种模式设计:
我需要将身份的 CRUD 移动到“业务类库”。为此我需要创建一个UserManager和RoleManager,但我不知道要创建UserManager(因为构造函数,需要8个参数)
namespace Business
{
public static class B_Manage
{
public static void CreateUser()
{
using (var IdentityDB = new IDBContext())
{
var roleStore = (IRoleStore<IdentityRole>)new RoleStore<IdentityRole>(IdentityDB);
var roleManager = new RoleManager<IdentityRole>(roleStore, null, null, null, null);
var userStore = new UserStore<IdentityUser>(IdentityDB);
var userManager = new UserManager<IdentityUser>()
}
}
}
}
我在其他网站看到了示例代码,但是当我参加创建一个新实例时,需要其他变量。
public async Task<ActionResult> Index()
{
var context = new ApplicationDbContext(); // DefaultConnection
var store = new UserStore<CustomUser>(context);
var manager = new UserManager<CustomUser>(store);
}
有人知道我可以在类库中创建 UserManager 吗?
【问题讨论】:
标签: .net-core asp.net-identity blazor usermanager