VNext. AspNet.Identity and Custom UserStore. UserStore exception

I am trying to understand vNext.
I wrote a 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 I tried to use the immutable AccountController from the Visual Studio template and have problems.
On entering, I get an ObjectDisposedException in UserStore.FindByNameAsync () - what is called UserStore.Dispose ().
In the UserManager code on github.com/aspnet Store.Dispose () is called only in UserManager.Dispose ().
I can just ignore the Dispose calls and everything works fine, but that is not good.
So I have no idea what to do

PS Question: what (and why) can cause UserStore.Dispose ()?

+5
source share
1 answer

In vNext, DI is built-in and controls the lifetime of identity services. You are probably trying to use the identity after the services have been deleted, the authentication services by default have a lifetime associated with the request, so for example, you are trying to insert a link to the user manager and reuse it for multiple requests, which will result in an ObjectDisposedException.

+1
source

Source: https://habr.com/ru/post/1201446/


All Articles