source: Add rules for AI Coding
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
---
|
||||
name: GenerateCQRSFeature
|
||||
description: Hướng dẫn tạo một feature theo chuẩn CQRS sử dụng MediatR (bao gồm Entity, Command/Query, Handler, và Controller).
|
||||
---
|
||||
|
||||
# GenerateCQRSFeature Skill
|
||||
|
||||
Khi user yêu cầu tạo một feature theo luồng **CQRS** với đầu vào bao gồm **Tên Feature** (VD: `Order`) và **Action** (VD: `Create`), bạn **BẮT BUỘC** phải thực hiện các bước sau để sinh ra code và file tương ứng:
|
||||
|
||||
## 1. Đầu ra thư mục và file (Outputs)
|
||||
|
||||
Dựa trên {FeatureName} và {Action}, hãy tạo các file sau (nếu action thuộc loại Read/Get thì đổi 'Commands' thành 'Queries'):
|
||||
|
||||
1. **Domain Entity**
|
||||
- **Đường dẫn**: `Domain/Entities/{FeatureName}.cs`
|
||||
- **Nội dung**: Lớp Entity cơ bản định nghĩa các thuộc tính.
|
||||
|
||||
2. **Command / Query**
|
||||
- **Đường dẫn**: `Application/Features/{FeatureName}s/Commands/{Action}{FeatureName}/{Action}{FeatureName}Command.cs`
|
||||
- **Nội dung**: Input model kế thừa từ `IRequest<TResponse>` của MediatR.
|
||||
|
||||
3. **Command / Query Handler**
|
||||
- **Đường dẫn**: `Application/Features/{FeatureName}s/Commands/{Action}{FeatureName}/{Action}{FeatureName}CommandHandler.cs`
|
||||
- **Nội dung**: Xử lý logic nghiệp vụ, implements `IRequestHandler<{Action}{FeatureName}Command, TResponse>`. Inject Repository hoặc service cần thiết vào đây.
|
||||
|
||||
4. **WebAPI Controller**
|
||||
- **Đường dẫn**: `WebAPI/Controllers/{FeatureName}sController.cs` (Lưu ý thêm số nhiều cho tên Controller nếu cần thiết).
|
||||
- **Nội dung**: REST API endpoints. **Yêu cầu:** Nhận DI `IMediator` qua constructor để điều hướng Request (ví dụ gọi `await _mediator.Send(command)`).
|
||||
|
||||
## 2. Cấu hình Dependency Injection (KHÔNG CẦN LÀM)
|
||||
|
||||
⚠️ **Lưu ý:** Như nguyên tắc thiết lập project, luồng CQRS **KHÔNG CẦN** update file cấu hình Dependency Injection (DI configuration).
|
||||
|
||||
Thư viện MediatR đã tự động quét (Auto-register) tất cả các lớp Handler kế thừa từ `IRequestHandler`, vì thế bạn **TUYỆT ĐỐI BỎ QUA** việc cập nhật các file config DI cho phần Handler này.
|
||||
Reference in New Issue
Block a user