orchardcore-module-creator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OrchardCore Module Creator

OrchardCore 模块创建指南

This skill guides you through creating new OrchardCore modules following project conventions.
本技能将引导你按照项目约定创建新的OrchardCore模块。

Prerequisites

前提条件

  • OrchardCore repository at
    D:\orchardcore
  • .NET SDK 10.0+ installed
  • OrchardCore 代码仓库位于
    D:\orchardcore
  • 已安装 .NET SDK 10.0+

Module Creation Workflow

模块创建流程

Step 1: Determine Module Type

步骤1:确定模块类型

What kind of module are you creating?
TypeDescriptionKey Components
Content PartAdds data/behavior to content itemsPart, Driver, Views
Content FieldCustom field typeField, Driver, Views
SettingsSite-wide configurationSiteSettings, Driver
Admin FeatureAdmin pages/toolsController, Views, Menu
APIREST endpointsApiController
Background TaskScheduled jobsIBackgroundTask
你要创建哪种类型的模块?
类型说明核心组件
内容部件为内容项添加数据/行为Part, Driver, Views
内容字段自定义字段类型Field, Driver, Views
设置站点级配置SiteSettings, Driver
管理功能管理页面/工具Controller, Views, Menu
APIREST 端点ApiController
后台任务定时任务IBackgroundTask

Step 2: Create Module Directory

步骤2:创建模块目录

bash
undefined
bash
undefined

Create module folder

Create module folder

mkdir src/OrchardCore.Modules/OrchardCore.YourModule cd src/OrchardCore.Modules/OrchardCore.YourModule
undefined
mkdir src/OrchardCore.Modules/OrchardCore.YourModule cd src/OrchardCore.Modules/OrchardCore.YourModule
undefined

Step 3: Create Required Files

步骤3:创建必需文件

Every module needs these three files:
  1. Manifest.cs - Module metadata
  2. Startup.cs - Service registration
  3. OrchardCore.YourModule.csproj - Project file
See
references/module-structure.md
for templates.
每个模块都需要以下三个文件:
  1. Manifest.cs - 模块元数据
  2. Startup.cs - 服务注册
  3. OrchardCore.YourModule.csproj - 项目文件
可参考
references/module-structure.md
获取模板。

Step 4: Add Components Based on Type

步骤4:根据模块类型添加组件

For Content Part modules:
Models/YourPart.cs
ViewModels/YourPartViewModel.cs
Drivers/YourPartDisplayDriver.cs
Views/YourPart.cshtml
Views/YourPart_Edit.cshtml
For Admin modules:
Controllers/AdminController.cs
Views/Admin/Index.cshtml
AdminMenu.cs
PermissionProvider.cs
For Data-storing modules:
Migrations.cs
Indexes/YourIndex.cs
See
references/patterns.md
for code templates.
对于内容部件模块:
Models/YourPart.cs
ViewModels/YourPartViewModel.cs
Drivers/YourPartDisplayDriver.cs
Views/YourPart.cshtml
Views/YourPart_Edit.cshtml
对于管理模块:
Controllers/AdminController.cs
Views/Admin/Index.cshtml
AdminMenu.cs
PermissionProvider.cs
对于数据存储模块:
Migrations.cs
Indexes/YourIndex.cs
可参考
references/patterns.md
获取代码模板。

Step 5: Register in Startup.cs

步骤5:在Startup.cs中注册

csharp
public override void ConfigureServices(IServiceCollection services)
{
    // Content part
    services.AddContentPart<YourPart>()
        .UseDisplayDriver<YourPartDisplayDriver>();
    
    // Services
    services.AddScoped<IYourService, YourService>();
    
    // Migrations (if storing data)
    services.AddDataMigration<Migrations>();
    
    // Permissions (if securing features)
    services.AddPermissionProvider<PermissionProvider>();
    
    // Navigation (if adding admin menu)
    services.AddNavigationProvider<AdminMenu>();
}
csharp
public override void ConfigureServices(IServiceCollection services)
{
    // Content part
    services.AddContentPart<YourPart>()
        .UseDisplayDriver<YourPartDisplayDriver>();
    
    // Services
    services.AddScoped<IYourService, YourService>();
    
    // Migrations (if storing data)
    services.AddDataMigration<Migrations>();
    
    // Permissions (if securing features)
    services.AddPermissionProvider<PermissionProvider>();
    
    // Navigation (if adding admin menu)
    services.AddNavigationProvider<AdminMenu>();
}

Step 6: Build and Test

步骤6:构建并测试

bash
undefined
bash
undefined

Build the module

Build the module

cd D:\orchardcore dotnet build src/OrchardCore.Modules/OrchardCore.YourModule
cd D:\orchardcore dotnet build src/OrchardCore.Modules/OrchardCore.YourModule

Run the application

Run the application

cd src/OrchardCore.Cms.Web dotnet run -f net10.0
cd src/OrchardCore.Cms.Web dotnet run -f net10.0

Enable the feature in Admin → Features

Enable the feature in Admin → Features

undefined
undefined

Quick Reference

快速参考

Naming Conventions

命名约定

ItemConventionExample
Module folder
OrchardCore.ModuleName
OrchardCore.Rating
Namespace
OrchardCore.ModuleName
OrchardCore.Rating
Feature ID
OrchardCore.ModuleName
OrchardCore.Rating
Content Part
NamePart
RatingPart
Driver
NamePartDisplayDriver
RatingPartDisplayDriver
View
PartName.cshtml
RatingPart.cshtml
Edit View
PartName_Edit.cshtml
RatingPart_Edit.cshtml
约定示例
模块文件夹
OrchardCore.ModuleName
OrchardCore.Rating
命名空间
OrchardCore.ModuleName
OrchardCore.Rating
功能ID
OrchardCore.ModuleName
OrchardCore.Rating
内容部件
NamePart
RatingPart
驱动程序
NamePartDisplayDriver
RatingPartDisplayDriver
视图
PartName.cshtml
RatingPart.cshtml
编辑视图
PartName_Edit.cshtml
RatingPart_Edit.cshtml

Common Dependencies

常见依赖项

Add to
.csproj
as needed:
xml
<!-- Core module support -->
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Module.Targets\OrchardCore.Module.Targets.csproj" />

<!-- Content management -->
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentManagement\OrchardCore.ContentManagement.csproj" />

<!-- Admin UI -->
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Admin\OrchardCore.Admin.csproj" />
根据需要添加到
.csproj
中:
xml
<!-- Core module support -->
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Module.Targets\OrchardCore.Module.Targets.csproj" />

<!-- Content management -->
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentManagement\OrchardCore.ContentManagement.csproj" />

<!-- Admin UI -->
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Admin\OrchardCore.Admin.csproj" />

Feature Categories

功能分类

Use in
Manifest.cs
:
  • Content Management
  • Content
  • Navigation
  • Security
  • Infrastructure
  • Theming
  • Developer
Manifest.cs
中使用:
  • Content Management
  • Content
  • Navigation
  • Security
  • Infrastructure
  • Theming
  • Developer

References

参考资料

  • references/module-structure.md
    - Directory layout and file templates
  • references/patterns.md
    - Code patterns (parts, drivers, handlers, etc.)
  • references/examples.md
    - Complete module examples
  • AGENTS.md
    (repo root) - Coding conventions and build commands
  • references/module-structure.md
    - 目录结构和文件模板
  • references/patterns.md
    - 代码模式(部件、驱动程序、处理程序等)
  • references/examples.md
    - 完整模块示例
  • AGENTS.md
    (仓库根目录)- 编码规范和构建命令