Clean Architecture 解决方案导入 ASP.NET Core Identity
Infrastructure 基础设施项目添加引用
Microsoft.AspNetCore.Identity.EntityFrameworkCore
注意:引用的Del程序集和.Net 框架版本之间的匹配关系。
Web 项目添加引用
Microsoft.AspNetCore.Authentication.JwtBearer
该包已经依赖Microsoft.IdentityModel.Tokens、System.IdentityModel.Tokens.Jwt,该包由Azure AD 团队提供,所以不在aspnetcore6 运行时中。
数据库上下文配置
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using TestIdentity.Infrastructure.Data.Model;
namespace TestIdentity.Infrastructure.Data;
public class IdDbContext : IdentityDbContext<User, Role, long>
{
public IdDbContext(DbContextOptions<IdDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//注意:必须注释以下行,否则会重复生成属于其它数据集的实例
//modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
}
}
浙公网安备 33010602011771号