学海无涯

导航

Clean Architecture 解决方案导入 ASP.NET Core Identity

Infrastructure 基础设施项目添加引用

Microsoft.AspNetCore.Identity.EntityFrameworkCore

 

注意:引用的Del程序集和.Net 框架版本之间的匹配关系。

Web 项目添加引用

Microsoft.AspNetCore.Authentication.JwtBearer

 该包已经依赖Microsoft.IdentityModel.TokensSystem.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);
  }
}

  

 

posted on 2024-04-17 09:07  宁静致远.  阅读(24)  评论(0)    收藏  举报