no_*_*one 5 asp.net-mvc objectdisposedexception asp.net-identity asp.net-identity-3 asp.net-core
我想了解vNext.
我编写了自定义UserStore,它与MongoDB一起使用并实现了这些接口:
public class UserStore : IUserStore<ApplicationUser>, IUserPasswordStore<ApplicationUser>, IUserSecurityStampStore<ApplicationUser>,
IUserLoginStore<ApplicationUser>, IUserClaimStore<ApplicationUser>, IUserEmailStore<ApplicationUser>, IUserRoleStore<ApplicationUser>,
IUserTwoFactorStore<ApplicationUser>
Run Code Online (Sandbox Code Playgroud)
在Startup.cs中添加:
app.UseServices(services =>
{
services.AddIdentity<ApplicationUser>()
.AddUserStore(() => { return new UserStore(); })
.AddUserManager<UserManager<ApplicationUser>>()
.AddHttpSignIn();
services.AddMvc();
});
Run Code Online (Sandbox Code Playgroud)
然后尝试使用Visual Studio模板中未更改的AccountController并遇到麻烦.
登录时,在UserStore.FindByNameAsync()中获取ObjectDisposedException - 称为UserStore.Dispose().
在github.com/aspnet上的UserManager代码中,Store.Dispose()仅在UserManager.Dispose()中调用.
我可以忽略Dispose的调用,一切正常,但这不是好方法.
所以我不知道该怎么做
PS问题是:什么(以及为什么)可以调用UserStore.Dispose()?
在 vNext 中,DI 是内置的并管理身份服务的生命周期。您可能会在服务被处置后尝试使用身份,默认情况下,身份服务的生命周期仅限于一个请求,因此,例如,如果您试图保留对用户管理器的引用并在多个请求中重用它,那么会导致 ObjectDisposeException。
| 归档时间: |
|
| 查看次数: |
1636 次 |
| 最近记录: |