I'm using asp.net core 7 and AspNetCore.Identity 7. I wanna register identity to dependency injection system in IoC layer:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Eshop.Entities;
namespace Eshop.IoCConfig;
public static class AddCustomServicesExtension
{
public static IServiceCollection AddCustomService(this IServiceCollection services)
{
// some code
services.AddIdentity<User, Role>();
return services;
}
}
But there's error:
IServiceCollection does not contain a definition for AddIdentity
CodePudding user response:
I solved this problem and use AddIdentityCore<TUser>
instead of AddIdentity<TUser, TRole>
:
services.AddIdentityCore<User>()
.AddRoles<Role>()
.AddEntityFrameworkStores<EshopDbContext>();