liveBook · Manning

UserManager<T>

As explained in Building Web APIs with ASP.NET Core

UserManager is an ASP.NET Core Identity service API that manages users and user-related operations, including role associations.

UserManager<T> is the ASP.NET Core Identity service for managing application users. In an account API, inject UserManager<ApiUser> into AccountController and use it to create users, find them by name, and verify passwords. section 9.2.6

Use UserManager<ApiUser> for these account and authorization tasks:

  • Check role membership with IsInRoleAsync and add users to roles with AddToRoleAsync during repeatable authentication-data seeding. section 9.4.2

Account registration

Validate RegisterDTO, copy its username and email into a new ApiUser, and call await _userManager.CreateAsync(newUser, input.Password). Check result.Succeeded before logging the creation and returning HTTP 201. Invalid email data produces HTTP 400, while a password that fails configured requirements produces an error response.

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains dependency injection and concrete asynchronous calls, but defers UserManager internals and Identity storage implementation.
Examples
Uses registration and login endpoints plus repeatable seeding of Moderator and Administrator roles.
What it assumes
Assumes C# controllers, DTO validation, dependency injection, and an ApiUser Identity model; introduces the required Identity services.
What you can do after
Operate UserManager through dependency-injected controller code to create users, authenticate credentials, and assign roles.
How it connects
Connects UserManager to ASP.NET Core Identity, dependency injection, AccountController, password validation, JWT, RoleManager, and role-based authorization.

Also explained in

Compare how 3 books explain UserManager<T> →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.