当前位置: 首页 > news >正文

【Abp.VNext】Abp.Vnext框架模块学习

1、Abp.Vnext-集成

Volo.Abp.Core

2、Abp.vNext-Web模块

Volo.Abp.AspNetCore.MVC

框架(framework文件夹)

七、Abp.vNext-应用模块-Identity身份认证

业务模块(modules文件夹->identity)

1、添加领域模型
Volo.Abp.Identity.Domain
typeof(AbpIdentityDomainMoule)

核心 IdentityUser模型类

2、实体框架:生成相应的表(生成迁移文件,生成对应的表)

1、集成

  • (1)、添加实体框架
Volo.Abp.Identity.EntityFrameworkCore
typeof(AbpIdentityEntityFrameworkCoreModule)
  • (2)、重写 OnModelCreating
 /// <summary>///  根据模型创建迁移文件。进一步创建表/// </summary>/// <param name="modelBuilder"></param>protected override void OnModelCreating(ModelBuilder builder){// 1、根据Identity 生成对应的数据库迁移文件。AbpIdentityDbProperties.DbTablePrefix = "Sys_";builder.ConfigureIdentity();
}
dotnet ef migrations add 迁移文件名称 -c 指定上下文
dotnet ef database update

会生成

1、abpusers #用户表
2、abproles #角色表
3...
  • (3)、集成Application
Volo.Abp.Identity.Application
typeof(AbpIdentityApplicationModule),
  • (4)、集成WebApi (自动添加Controller
Volo.Abp.Identity.HttpApi
typeof(AbpIdentityHttpApiModule),

启动会报错:报权限错误(因为:[Authorize(IdentityPermissions.Users.Default)] 代表有权限才能调用)
需要引用权限模块(因为引用了权限模块的EfCore : Volo.Abp.PermissionManagement.EntityFrameworkCore

Volo.Abp.PermissionManagement.EntityFrameworkCore
typeof(AbpPermissionManagementEntityFrameworkCoreModule)

多了Role(角色)、User(用户)、UserLookUp(向上查找、搜索用户用的) 三个模块

添加身份认证权限,否则调用添加用户会报错权限问题

// 10、添加身份认证
context.Services.AddAuthentication().AddCookie();// 11、添加权限校验
context.Services.AddAuthorization();// 12、去掉所有的权限
context.Services.AddAlwaysAllowAuthorization();

注意:需要先添加角色,否则会报 角色字符串不存在。,然后再调用创建用户接口 才会成功!

1、ConfigureAwait(false) 是一种优化手段,确保异步操作完成后不会强制切换回原始上下文,通常用于提升性能并避免死锁风险。2、.ToListAsync(cancellationToken: cancellationToken) 的作用是:异步执行查询,将结果转为 List<T>。
支持取消,通过 CancellationToken 实现可控的中断机制。
在你的代码中,它高效地加载了用户与组织单元角色的关联数据,同时允许外部控制查询的生命周期。

它有自己的数据库上下文 IdentityDbContext ,这个模块用的也是自己的数据库上下文。

2、自定义框架
(1)、自定义表前缀(EbusinessModule)

 public override void ConfigureServices(ServiceConfigurationContext context){// 13、identity身份模块访问新前缀AbpIdentityDbProperties.DbTablePrefix = "Sys_";
}/// <summary>
///  根据模型创建迁移文件。进一步创建表(ABPEbusinessContext)
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder builder)
{// 1、根据Identity 生成对应的数据库迁移文件。AbpIdentityDbProperties.DbTablePrefix = "Sys_";
}

不建议改源码 表的后缀

(2)、自定义用户模型、

/// <summary>
/// (1)、用户自定义字段
/// </summary>
public class SysUser : IdentityUser
{public string CreateTony { set; get; }
}public DbSet<SysUser> sys_users { set; get; }/// <summary>/// (2.1)用户自定义仓储 用来实现abp提供的仓储/// </summary>public interface IUserABPRepository : IRepository<SysUser, Guid>{Task<SysUser> FindByNormalizedUserNameAsync([NotNull] string normalizedUserName,bool includeDetails = true,CancellationToken cancellationToken = default);...}/// <summary>/// (2.2)用户仓储自定义实现/// </summary>[Dependency(ServiceLifetime.Singleton)]public class UserABPRepository : EfCoreRepository<ABPEbusinessContext, SysUser, Guid>, IUserABPRepository{public UserABPRepository(IDbContextProvider<ABPEbusinessContext> dbContextProvider) : base(dbContextProvider){}
...
}//3. 改动dto/// <summary>/// 4.1 用户自定义service/// </summary>public interface IUserABPService : ICrudAppService<SysUserDto,Guid,GetSysUserInput,SysUserCreateDto,SysUserUpdateDto>{Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id);
}/// <summary>/// 4.2 用户service自定义实现/// </summary>[Dependency(ServiceLifetime.Singleton)]//[Authorize]public class UserABPService : CrudAppService<SysUser,SysUserDto,Guid,GetSysUserInput,SysUserCreateDto,SysUserUpdateDto>, IUserABPService, IRemoteService{public UserABPService(IUserABPRepository userABPRepository) : base(userABPRepository){}public Task<SysUserDto> FindByEmailAsync(string email){throw new NotImplementedException();}
}/// <summary>
/// 5、使用:配置自定义映射类型。dto---->实体,
/// </summary>
public class EbusinessAutoMapperProfile : Profile
{public EbusinessAutoMapperProfile(){// 1、具体类型映射配置CreateMap<ProductDto, Product>();// 2、配置实体到dto的类型CreateMap<Product, ProductDto>();CreateMap<SysUser,SysUserDto>().ReverseMap();}
}/// <summary>/// 6、用户自定义字段/// </summary>public class SysUserDto : ExtensibleFullAuditedEntityDto<Guid>, IMultiTenant, IHasConcurrencyStamp, IHasEntityVersion{public string CreateTony { set; get; }public Guid? TenantId { get; set; }public string UserName { get; set; }public string Name { get; set; }public string Surname { get; set; }public string Email { get; set; }public bool EmailConfirmed { get; set; }public string PhoneNumber { get; set; }public bool PhoneNumberConfirmed { get; set; }public bool IsActive { get; set; }public bool LockoutEnabled { get; set; }public DateTimeOffset? LockoutEnd { get; set; }public string ConcurrencyStamp { get; set; }public int EntityVersion { get; set; }}
八、Abp.vNext-应用模块-Account账户模块

系统提供的登录和注册

  • 注册:将用户信息存储到数据库
  • 登录:将用户信息存储到Cookie内存。

缺少Domain(领域层)、EFCore层

//集成应用模块,account账户模块
typeof(AbpAccountApplicationModule),
typeof(AbpAccountHttpApiModule),
typeof(AbpAccountWebModule)
九、Abp.vNext-应用模块-Permission权限模块
abppermission
http://www.lryc.cn/news/619592.html

相关文章:

  • 服务器如何应对SYN Flood攻击?
  • 如何管理需求文档的版本历史
  • 【嵌入式电机控制#31】FOC:霍尔安装误差的补偿
  • MyBatis 中 XML 与 DAO 接口的位置关系及扫描机制详解
  • 深度学习——03 神经网络(2)-损失函数
  • Flutter网络请求实战:Retrofit+Dio完美解决方案
  • 51单片机-51单片机最小系统
  • 区块链DApp:颠覆未来的去中心化应用
  • 性能优化之通俗易懂学习requestAnimationFrame和使用场景举例
  • PyTorch生成式人工智能——基于Transformer实现文本转语音
  • 浅谈TLS 混合密钥交换:后量子迁移过渡方案
  • [TG开发]简单的回声机器人
  • 科技赋能虚拟形象:3D人脸扫描设备的应用与未来
  • vscode+phpstudy+xdebug如何调试php
  • 【R语言】R语言的工作空间映像(workspace image,通常是.RData)详解
  • YOLO v1 输出结构、预测逻辑与局限性详解
  • 教育元宇宙:一场重构教育生态的数字革命
  • 在实验室连接地下车库工控机及其数据采集设备
  • 面向局部遮挡场景的目标检测系统设计与实现
  • 开源WAF新标杆:雷池SafeLine用语义分析重构网站安全边界
  • Go语言实战案例:使用Gin处理路由参数和查询参数
  • .net\c#web、小程序、安卓开发之基于asp.net家用汽车销售管理系统的设计与实现
  • Redis学习——Redis的十大类型String、List、Hash、Set、Zset
  • SQL详细语法教程(一)--数据定义语言(DDL)
  • PCIe Base Specification解析(十)
  • 基于机器学习的自动驾驶汽车新型失效运行方法
  • BGP综合实验_Te. BGP笔记
  • Python实战教程:PDF文档自动化编辑与图表绘制全攻略
  • Blender模拟结构光3D Scanner(一)外参数匹配
  • 解决:nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module