SuperAPI AI 工具集

abp-contract-scaffolding

编程与开发

查看项目

更新于 10-16 02:24

技能介绍

用途

ABP Contract Scaffolding 用于从技术设计生成 ABP 框架的 Application.Contracts 层代码,以支持并行开发工作流。

契约脚手架将接口设计与实现分离,从而支持:

  • abp-developer 针对已定义的接口进行实现
  • qa-engineer 针对接口编写测试(在实现存在之前)
  • 在 /add-feature 工作流中实现真正的并行执行

主要能力

该技能可生成以下内容:

  • 服务接口(I{Entity}AppService)
  • 输出 DTO({Entity}Dto)
  • 创建输入 DTO(Create{Entity}Dto)
  • 更新输入 DTO(Update{Entity}Dto)
  • 列表过滤/分页输入 DTO(Get{Entity}sInput)
  • 权限常量({Entity}Permissions)

生成的项目结构为:

{Project}.Application.Contracts/
├── {Feature}/
│   ├── I{Entity}AppService.cs      # Service interface
│   ├── {Entity}Dto.cs              # Output DTO
│   ├── Create{Entity}Dto.cs        # Create input
│   ├── Update{Entity}Dto.cs        # Update input
│   └── Get{Entity}sInput.cs        # List filter/pagination
└── Permissions/
    └── {Entity}Permissions.cs      # Permission constants

使用方式

该技能由 backend-architect 智能体在 /add-feature 的 Phase 1 中使用:

Phase 1:backend-architect 生成:

docs/features/{feature}/technical-design.md
Application.Contracts/{Feature}/I{Entity}AppService.cs
Application.Contracts/{Feature}/{Entity}Dto.cs
Application.Contracts/{Feature}/Create{Entity}Dto.cs
Application.Contracts/{Feature}/Update{Entity}Dto.cs
Application.Contracts/{Feature}/Get{Entity}sInput.cs
Application.Contracts/Permissions/{Entity}Permissions.cs

Phase 2(并行):

abp-developer: Implements against interface
qa-engineer: Writes tests against interface

生成契约时需检查:

  • 接口继承 IApplicationService
  • 所有 DTO 位于正确的命名空间 {ProjectName}.{Feature}
  • 输出 DTO 继承 FullAuditedEntityDto<Guid>(或合适的基类)
  • 过滤 DTO 继承 PagedAndSortedResultRequestDto
  • 权限常量遵循 {Project}.{Resource}.{Action} 模式
  • 包含 XML 文档注释
  • 属性与技术设计规范一致
  • 必填与可选属性标记正确
  • 集合属性已初始化(= new() 或 = [])

适用场景

  • 后端架构师在创建技术设计时生成契约
  • 准备并行实现与测试
  • 在实现开始前定义 API 契约
  • 接口优先的开发方式

常见模式

激活/停用模式

当实体支持激活生命周期时:

// In interface
Task<{Entity}Dto> ActivateAsync(Guid id);
Task<{Entity}Dto> DeactivateAsync(Guid id);

// In permissions
public const string Activate = GroupName + ".Activate";
public const string Deactivate = GroupName + ".Deactivate";

// In filter DTO
public bool? IsActive { get; set; }

层级实体模式

当实体具有父子关系时:

// In output DTO
public Guid? ParentId { get; set; }
public string? ParentName { get; set; }
public List<{Entity}Dto> Children { get; set; } = new();

// In interface
Task<List<{Entity}Dto>> GetChildrenAsync(Guid parentId);
Task MoveAsync(Guid id, Guid? newParentId);

// In filter DTO
public Guid? ParentId { get; set; }
public bool IncludeChildren { get; set; }

查找/引用模式

用于下拉列表和引用:

// Lightweight DTO for dropdowns
public class {Entity}LookupDto
{
    public Guid Id { get; set; }
    public string Name { get; set; } = string.Empty;
}

// In interface
Task<List<{Entity}LookupDto>> GetLookupAsync();

批量操作模式

当需要批量操作时:

// In interface
Task<int> DeleteManyAsync(List<Guid> ids);
Task<List<{Entity}Dto>> CreateManyAsync(List<Create{Entity}Dto> inputs);

// In permissions
public const string DeleteMany = GroupName + ".DeleteMany";

命名约定

组件 模式 示例
接口 I{Entity}AppService IBookAppService
输出 DTO {Entity}Dto BookDto
创建 DTO Create{Entity}Dto CreateBookDto
更新 DTO Update{Entity}Dto UpdateBookDto
过滤 DTO Get{Entity}sInput GetBooksInput
查找 DTO {Entity}LookupDto BookLookupDto
权限 {Entity}Permissions BookPermissions

相关技能

  • abp-framework-patterns - 完整 ABP 模式,包括实现
  • technical-design-patterns - 技术设计文档模板
  • api-design-principles - REST API 设计最佳实践

限制

资料未提供该技能的具体安装命令、收费方式、支持平台或运行环境要求,暂未提供。