Как пофиксить ошибку Unable to resolve service?

Добавил в проект asp.net UserManager. При регистрации выходит ошибка. Если убираю UserManager, то все работает нормально.

Ошибка:
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UI.Services.IEmailSender' while attempting to activate 'Libr.Areas.Identity.Pages.Account.RegisterModel'.

и Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options =>
        options.UseNpgsql(
            Configuration.GetConnectionString("DefaultConnection")));


    services.AddDbContext<BooksContext>(options =>
       options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
    services.AddDbContext<CartContext>(options =>
     options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
    services.AddDbContext<OrdersContext>(options =>
    options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));

    //services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
    //    .AddEntityFrameworkStores<ApplicationDbContext>();
    services.AddIdentity<IdentityUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();



    services.AddScoped<BookRepository>();
    services.AddScoped<CartRepository>();
    services.AddScoped<OrdersRepository>();
    services.AddScoped<ApplicationDbContext>();
    services.AddScoped<UserManager<IdentityUser>>();

    //services.AddTransient<UserManager<IdentityUser>>();
    //services.AddTransient<ApplicationDbContext>();

    services.AddRazorPages();
}

Ответы (1 шт):

Автор решения: motpfofs

Ошибка заключается в том, что UserManager зависит от IEmailSender, а вы не объявили его в вашем DI контейнере. Добавьте:

services.AddScoped<IEmailSender, EmailSender>();
→ Ссылка