我正在一个项目中,我想从身份中分离出DbContext,但是在注册自定义存储区时,应用程序将抛出StackOverflowException。
这是我的自定义商店:
UserStore:
public class UserStoreProvider : IUserStore<User>, IUserPasswordStore<User>
{ IUserService _userService;
public UserStoreProvider(IUserService userService)
{ _userService = userService;
}
public async Task<IdentityResult> CreateAsync(User user, CancellationToken cancellationToken)
{
await _userService.CreateAsync(AutoMapper.Mapper.Map(user, new CommonModels.User.User()));
return IdentityResult.Success;
}
public Task<IdentityResult> DeleteAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
//Some implementation is not pasted here
}
RoleStore:
public class RoleStoreProvider : IRoleStore<Role>
{
public Task<IdentityResult> CreateAsync(Role role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<IdentityResult> DeleteAsync(Role role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public void Dispose()
{
Dispose();
}
public Task<Role> FindByIdAsync(string roleId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<Role> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
//Some implementation is not pasted here
}
和服务注册:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddIdentity<User, Role>()
.AddRoles<Role>()
.AddUserStore<UserStoreProvider>()
.AddRoleStore<RoleStoreProvider>().AddDefaultUI();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
运行该应用程序后,尝试访问页面,但该应用程序突然关闭并抛出StackOverflowException。
其他详细信息:
使用Dotnet core 2.2运行
Visual Studio 2019
有什么主意吗?