5

I'm trying to understand vNext.
I wrote custom UserStore, that works with MongoDB and implements these interfaces:

  public class UserStore : IUserStore<ApplicationUser>, IUserPasswordStore<ApplicationUser>, IUserSecurityStampStore<ApplicationUser>,
    IUserLoginStore<ApplicationUser>, IUserClaimStore<ApplicationUser>, IUserEmailStore<ApplicationUser>, IUserRoleStore<ApplicationUser>,
    IUserTwoFactorStore<ApplicationUser>

In Startup.cs added:

app.UseServices(services =>
        {

            services.AddIdentity<ApplicationUser>()
                .AddUserStore(() => { return new UserStore(); })
                .AddUserManager<UserManager<ApplicationUser>>()
                .AddHttpSignIn();

            services.AddMvc();
        });

Then tried to use unchanged AccountController from Visual Studio template and have troubles.
When signing in i getting ObjectDisposedException in UserStore.FindByNameAsync() -- something called UserStore.Dispose().
In UserManager code on github.com/aspnet Store.Dispose() called only in UserManager.Dispose().
I can just ignore calls of Dispose and all works fine, but this is not good way.
So i have no ideas what shall i do

P.S. The Question is: what (and why) can call UserStore.Dispose()?

4

1 回答 1

1

在 vNext 中,DI 内置并管理身份服务的生命周期。您可能会在服务被释放后尝试使用身份,默认情况下,身份服务的生命周期仅限于请求,因此,例如,如果您尝试挂起对用户管理器的引用并在多个请求中重用它,那会导致 ObjectDisposedException。

于 2014-09-03T21:11:33.533 回答