scaffold-write
Guide for adding a new write operation (command/mutation) to the Backend. Focuses on Event Sourcing, Wolverine commands, and Projections.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Follow this guide to implement a state-changing operation in the Backend (ApiService) using strict project standards.
-
Define the Domain Event
- Create a
recordinsrc/BookStore.ApiService/Events/. -
Naming: Past tense (e.g.,
BookPublished, notPublishBook). -
Timestamps: MUST use
DateTimeOffset(neverDateTime). -
IDs: MUST use
Guid.CreateVersion7()(neverGuid.NewGuid()). -
Example:
public record BookPublished(Guid Id, DateTimeOffset Timestamp);
- Create a
-
Define the Command
- Create a
recordinsrc/BookStore.ApiService/Commands/{Resource}/(e.g.,Commands/Books/). -
Template:
templates/Command.cs
- Create a
-
Implement the Wolverine Handler
- Create/Update
src/BookStore.ApiService/Handlers/{Resource}/{Resource}Handlers.cs. -
Template:
templates/Handler.cs
- Create/Update
-
Expose the Endpoint (Backend)
- Open
src/BookStore.ApiService/Endpoints/{Resource}Endpoints.cs. -
Template:
templates/Endpoint.cs
- Open
-
Update Read Model (Projections)
- Open
src/BookStore.ApiService/Projections/{Resource}Projection.cs. - Implement
CreateorApplymethods.
- Open
-
Enable Real-time Updates (SSE)
-
Notification: Create
record {Event}Notificationinsrc/Shared/BookStore.Shared/Notifications/DomainEventNotifications.cs. -
Listener: Update
src/BookStore.ApiService/Infrastructure/MartenCommitListener.cs.- Add
case {Resource}Projection proj:inProcessDocumentChangeAsync. - Implement
Handle{Resource}ChangeAsyncto.NotifyAsync()the new notification.
- Add
- Reference: See real-time-notifications for the complete data flow.
-
Notification: Create
-
Client Integration
-
Interface: Create
src/Client/BookStore.Client/I{Action}{Resource}Endpoint.csmanually. -
DTOs: If a Request DTO is needed, create it in
src/Shared/BookStore.Shared/Models/(do not rely on auto-generation). -
Registration: Add to
BookStoreClientExtensions.cs.
-
Interface: Create
// turbo 8. Verify
- Run
/verify-featureto ensure build, format, and tests pass.
Related Skills
Prerequisites:
- For complex aggregates, consider
/scaffold-aggregatefirst to create the domain model
Next Steps:
-
/scaffold-read- Add query endpoints for the new resource -
/scaffold-frontend-feature- Create UI for the new feature -
/scaffold-test- Create integration tests -
/verify-feature- Complete verification
Specialized Skills:
-
/scaffold-aggregate- Generate event-sourced aggregates with Apply methods -
/scaffold-projection- Generate read model projections for queries
See Also:
- scaffold-aggregate - Detailed aggregate patterns
- scaffold-projection - Projection creation
- wolverine-guide - Wolverine command/handler patterns
- ApiService AGENTS.md - Backend patterns and conventions
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!