我正在开发 .net core 项目。我的项目结构有 4 个项目。
我已经实现了实体框架核心。并尝试使用 Usermanager 来插入数据。现在,当我从控制器(Student_Web)调用方法“CreateAsync”时,它工作正常并且用户插入。但我想在Student_Service中实现数据库操作。因此,当我从 UserService 调用“CreateAsync”时,它会给出错误“无法访问已处置的对象。\r\n对象名称:'UserManager`1”
我从控制器调用此接口 IUserService。这是我在 UserService 中的代码。
请帮我解决这个问题。
public class UserService : IUserService
{
#region Properties
private readonly IDbContext _context;
private readonly UserManager<ApplicationUser> _userManager;
private readonly RoleManager<IdentityRole<int>> _roleManager;
#endregion
#region Consturctor
public UserService(
IDbContext context
, UserManager<ApplicationUser> userManager
, RoleManager<IdentityRole<int>> roleManager
{
_context = context;
_userManager = userManager;
_roleManager = roleManager;
}
#endregion
#region Methods
public async Task<bool> Create(NewUsers model)
{ …Run Code Online (Sandbox Code Playgroud) c# claims-based-identity asp.net-identity asp.net-core ef-core-3.1