Question

I am looking for the correct way to get access to the UserManager<MyUser> object outside of a controller using the most recent incarnation of ASP.NET MVC 5 and Entity Framework 7.

I want to seed my database with users in my seed class, but I have been unable to find a way to access the UserManager object to do so.

The Visual Studio 2015 Update 1 default ASP.NET template reveals the statement app.UseIdentity() in the Startup.Configure method while the Account controller accepts the UserManager<MyUser> in its constructor.

How do I access the UserManager in other classes so that I can create seed users?

1
1
3/10/2017 1:19:34 AM

Accepted Answer

The UserManager is registered with the built-in dependency injection. You can add

UserManager<ApplicationUser> userManager

to the constructor of the consuming class, and you should be able to use it. Assuming ASP.NET is responsible for the construction of that class.

0
3/10/2017 1:21:20 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow