‹ 首页

abp-dependency-rules

@burakdmir · 收录于 昨天 · 上游提交 2 周前

ABP Framework v10.x (10.4/10.5) layer dependency rules: layer direction (Domain.Shared→Domain→Application.Contracts→Application→HttpApi→Host), project reference matrix, anti-patterns (no DbContext in Application, don't expose IQueryable, don't return entity as DTO). Use when you need project/layer architecture or dependency rules in ABP.

适合你,如果正在使用 ABP Framework 并需要确保项目分层依赖合规。

/ 通过 npx 安装 校验哈希
npx oh-my-skill add burakdmir/abp-skills/abp-dependency-rules
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- burakdmir/abp-skills/abp-dependency-rules
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify burakdmir/abp-skills/abp-dependency-rules
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
13GitHub stars
~885上下文体积 · 单文件
索引托管

怎么用

商店整理自技能原文 · 版本 ce71259 · 表述以原文为准
它做什么

安装此技能后,Claude 会依据 ABP Framework v10.x 的官方规范,回答关于项目层依赖方向、引用矩阵和反模式的问题。它不会允许在 Application 层使用 DbContext、暴露 IQueryable 或返回实体作为 DTO。

什么时候触发

当你询问 ABP 项目层架构或依赖规则时触发。例如:提出“ABP layer architecture”、“ABP dependency rules”或“ABP 层架构”等关键词。

装好后可以这样说
Claude 会解释层依赖方向并指出错误做法。
技能原文 SKILL.md作者撰写 · MIT · ce71259

ABP Framework — Dependency Rules

ABP Framework v10.x (10.4/10.5) layer dependency rules and project-structure guardrails. Correct dependency direction, use of abstractions, and common violations.

Trigger
  • "ABP layer architecture"
  • "ABP dependency rules"
  • "ABP layer dependency"
  • "ABP project references"
  • "ABP where is DbContext"
  • "ABP architecture guardrail"
Core Principles (All Templates)
  1. Domain logic never depends on infrastructure (no DbContext in Domain/Application)
  2. Use abstractions (interfaces) for dependencies
  3. An upper layer depends on a lower layer, never the reverse
  4. Data access goes through the repository, not directly through DbContext
Layered Template Structure
Domain.Shared    → Constants, enums, localization keys
       ↑
    Domain       → Entity, repository interface, domain service
       ↑
Application.Contracts → App service interface, DTO
       ↑
  Application    → App service implementation
       ↑
   HttpApi       → REST controller (optional)
       ↑
     Host        → Final application with DI + middleware
Reference Matrix

| Project | Can reference | Referenced by | |---|---|---| | Domain.Shared | (none) | All | | Domain | Domain.Shared | Application, Data layer | | Application.Contracts | Domain.Shared | Application, HttpApi, Clients | | Application | Domain, Contracts | Host | | EntityFrameworkCore / MongoDB | Domain | Host only | | HttpApi | Contracts only | Host |

❌ Never Do
// DbContext directly in the Application layer
public class BookAppService : ApplicationService
{
    private readonly MyDbContext _dbContext; // ❌ WRONG — use a repository
}

// Domain depending on application
public class BookManager : DomainService
{
    private readonly IBookAppService _appService; // ❌ WRONG
}

// HttpApi depending on the Application implementation
public class BookController : AbpController
{
    private readonly BookAppService _bookAppService; // ❌ WRONG — use the interface
}
✅ Always Do
public class BookAppService : ApplicationService
{
    private readonly IBookRepository _bookRepository; // ✅ repository abstraction
}

public class BookController : AbpController
{
    private readonly IBookAppService _bookAppService; // ✅ contract (interface)
}
Repository Location
// Interface → Domain project
public interface IBookRepository : IRepository<Book, Guid>
{
    Task<Book> FindByNameAsync(string name);
}

// Implementation → EntityFrameworkCore project
public class BookRepository : EfCoreRepository<MyDbContext, Book, Guid>, IBookRepository { }

// or MongoDB project
public class BookRepository : MongoDbRepository<MyDbContext, Book, Guid>, IBookRepository { }
Multiple Applications Scenario (Admin + Public)
MyProject.Admin.Application    — Admin-specific services
MyProject.Public.Application   — Public-specific services
MyProject.Domain               — Shared domain (both reference it)
  • The Admin and Public application layers DO NOT reference each other
  • Domain logic is shared, application logic is not
  • Each vertical can have its own DTO (even if similar)
Common Violations

| Violation | Impact | Solution | |---|---|---| | DbContext in Application | Breaks DB independence | Use a repository | | Returning entity as DTO | Exposes internal structure | Map to a DTO | | IQueryable in interface | Breaks the abstraction | Return a concrete type | | App service call across modules | Tight coupling | Use an event or domain |

Best Practices
  1. Stick to the dependency direction — top to bottom, never the reverse
  2. No DbContext in Domain/Application — only the repository abstraction
  3. Repository interface in Domain, implementation in the Data layer
  4. Don't expose IQueryable — return a concrete type
  5. Don't let entities cross the boundary — always a DTO
  6. Use events/domain for cross-module communication — not a direct app service call
Related
  • [Framework Core](../abp-framework/SKILL.md) — layer/template overview
  • [DDD](../abp-ddd/SKILL.md) — domain/application design
  • [EF Core](../abp-efcore/SKILL.md) — repository implementation
  • [Modularity](../abp-modularity/SKILL.md) — module dependencies
  • [Development Flow](../abp-development-flow/SKILL.md) — which code in which layer
  • ABP Docs: https://abp.io/docs/latest/framework/architecture/best-practices
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。