‹ 首页

abp-modularity

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

ABP Framework v10.x (10.4/10.5) modularity: AbpModule, [DependsOn], module lifecycle, plugin modules, modular monolith. Use when creating a module, defining module dependencies, or building a modular architecture in ABP.

适合你,如果你在使用 ABP Framework 构建模块化应用

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

怎么用

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

Claude 能指导你使用 ABP Framework v10.x 创建和管理模块,包括定义模块类、声明依赖、使用生命周期方法,以及实现插件模块和模块化单体架构。

什么时候触发

当你提到“ABP modularity”、“创建ABP模块”、“ABP DependsOn”等关键词,或询问模块依赖、生命周期、插件模块时触发。

装好后可以这样说
Claude 会生成模块类代码并解释依赖声明。
技能原文 SKILL.md作者撰写 · MIT · ce71259

ABP Framework — Modularity

A guide to modular application development in ABP Framework v10.x (10.4/10.5). The module system, dependency management, plugin modules, and best practices.

Trigger
  • "ABP modularity"
  • "create an ABP module"
  • "ABP DependsOn"
  • "ABP plugin module"
  • "ABP modular monolith"
  • "ABP module dependency"
What Is Modularity

ABP supports building fully modular applications and systems. Each module can contain its own entities, services, database integration, APIs, and UI components.

Module Class
[DependsOn(
    typeof(AbpAspNetCoreMvcModule),
    typeof(AbpEntityFrameworkCoreModule),
    typeof(AbpAutofacModule)
)]
public class BlogModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context) { }
    
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        // DI registration, module configuration
        Configure<AbpDbConnectionOptions>(options =>
        {
            options.ConnectionStrings.Default = "...";
        });
    }
    
    public override void OnApplicationInitialization(ApplicationInitializationContext context)
    {
        var app = context.GetApplicationBuilder();
        var env = context.GetEnvironment();
        
        if (env.IsDevelopment())
            app.UseDeveloperExceptionPage();
        
        app.UseMvcWithDefaultRoute();
    }
    
    public override void OnApplicationShutdown(ApplicationShutdownContext context) { }
}
Lifecycle Methods

| Method | When It Runs | Usage | |---|---|---| | PreConfigureServices | Before all ConfigureServices | Early configuration | | ConfigureServices | Service registration | DI registration, module settings | | PostConfigureServices | After all ConfigureServices | Late configuration | | OnPreApplicationInitialization | Before init | Pre-init logic | | OnApplicationInitialization | Application startup | Middleware pipeline | | OnPostApplicationInitialization | After init | Post-init logic | | OnApplicationShutdown | Application shutdown | Cleanup logic |

An Async version of each method is also available.

Module Dependencies
// Multiple within a single DependsOn
[DependsOn(typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule))]
public class BlogModule : AbpModule { }

// Multiple attributes
[DependsOn(typeof(AbpAspNetCoreMvcModule))]
[DependsOn(typeof(AbpAutofacModule))]
public class BlogModule : AbpModule { }

At startup, ABP inspects the dependency graph and starts/shuts down modules in the correct order.

Additional Assembly

In rare cases, if your module consists of more than one assembly:

[DependsOn(...)]
[AdditionalAssembly(typeof(BlogService))]  // A type from the target assembly
public class BlogModule : AbpModule { }
Warning: Use AdditionalAssembly only when truly needed. Normally DependsOn should be preferred.
Framework vs Application Modules

| Type | Description | Example | |---|---|---| | Framework Module | Infrastructure, integration, abstraction | Caching, EF Core, Validation, Logging | | Application Module | Functional/business features | Blogging, Identity, Tenant Management |

Plugin Modules

Modules that can be loaded dynamically at runtime:

[DependsOn(typeof(AbpKernelModule))]
public class MyPluginModule : AbpModule { }

Plugin modules:

  • Are not referenced at compile-time
  • Are loaded at runtime from a specified directory
  • Are used for hot-plug-like scenarios
Module Development Best Practices
  1. Package according to DDD layers: ``` Acme.Blog/ ├── Acme.Blog.Domain.Shared # Constants, enums, localization ├── Acme.Blog.Domain # Entities, repositories (interface) ├── Acme.Blog.Application.Contracts # DTOs, service interfaces ├── Acme.Blog.Application # Application services ├── Acme.Blog.EntityFrameworkCore # DbContext, migrations ├── Acme.Blog.HttpApi # API controllers └── Acme.Blog.HttpApi.Client # Dynamic C# clients ```
  1. Design independently of the database provider — don't make the Domain/Application layers depend on EF Core
  1. Each module can define its own connection string: ```csharp Configure<AbpDbConnectionOptions>(options => { options.ConnectionStrings["Blog"] = "..."; }); ```
  1. Use the Options pattern for module configuration: ```csharp public class BlogOptions { public int MaxPostLength { get; set; } = 5000; }

// Configure it in the Module Configure<BlogOptions>(options => options.MaxPostLength = 10000); ```

  1. Use IRepository for reusable modules — don't use DbContext directly
Creating a Module with the CLI
# DDD module
abp new-module Acme.Blog -t module:ddd

# Modern module
abp new-module Acme.Blog --modern

# Add to a specific solution
abp new-module Acme.Blog -t module:ddd -ts Acme.Crm.sln

# With EF + MVC support
abp new-module Acme.Blog -t module:ddd -d ef -u mvc
Installing a Module
# Install a NuGet module
abp install-module Volo.Blogging

# Install a local module
abp install-local-module ../Acme.Blogging

# Add a package
abp add-package Volo.Abp.Blogging
Module Extending

Extending pre-built modules:

// Extending an entity
ObjectExtensionManager.Instance
    .MapEfCoreProperty<IdentityUser, string>(
        "Title",
        (entityBuilder, propertyBuilder) =>
        {
            propertyBuilder.HasMaxLength(64);
        }
    );
Modular Monolith

A modular monolith offers the advantages of microservices within a single process:

  • Each module defines its own bounded context
  • Inter-module communication happens via interfaces
  • Deployment is as a single application
  • It can later be converted into a microservice
abp new Acme.Crm --template app-nolayers --modern --modular

Related
  • [Framework Core](../abp-framework/SKILL.md) — AbpModule, lifecycle, [DependsOn]
  • [Dependency Injection](../abp-dependency-injection/SKILL.md) — module-based service registration
  • [Dependency Rules](../abp-dependency-rules/SKILL.md) — inter-module dependency rules
  • [Microservices](../abp-microservices/SKILL.md) — from modular monolith to microservice
  • ABP Docs: https://abp.io/docs/latest/framework/architecture/modularity/basics
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

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