T代表Id的数据类型,比如GUID;
示例
1、安装NuGet包
ContactsManager.Core
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.6"
/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore"
Version="8.0.6" />
ContactsManager.UI
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.6"
/>
2、新建ApplicationUser.cs和ApplicationRole.cs
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContactsManager.Core.Domain.IdentityEntities
{
public class ApplicationUser : IdentityUser<Guid>
{
public string? PersonName { get; set; }
}
}
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContactsManager.Core.Domain.IdentityEntities
{
public class ApplicationRole : IdentityRole<Guid>
{
}
}
3、更新ContactsManager.Infrastructure项目中的ApplicationDbContext.cs,将DbContext改成IdentityDbContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser,
ApplicationRole,Guid>
IdentityDbContext相比DbContext多了DbSet以及Identity需要的内容,功能更加强大。
Gitee获取源码: