add brain
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
---
|
||||
name: GenerateCQRSFeature
|
||||
description: Guide to generating a CQRS-based feature using MediatR (including Entity, Command/Query, Handler, and Controller).
|
||||
---
|
||||
|
||||
# GenerateCQRSFeature Skill
|
||||
|
||||
When a user requests to create a feature using the **CQRS** pattern, providing the **Feature Name** (e.g., `Order`) and **Action** (e.g., `Create`), you **MUST** follow these steps to generate the corresponding code and files:
|
||||
|
||||
## 1. Directory and File Outputs
|
||||
|
||||
Based on the {FeatureName} and {Action}, create the following files (if the action is Read/Get, change 'Commands' to 'Queries'):
|
||||
|
||||
1. **Domain Entity**
|
||||
- **Path**: `Domain/Entities/{FeatureName}.cs`
|
||||
- **Content**: A basic Entity class defining the properties.
|
||||
|
||||
2. **Command / Query**
|
||||
- **Path**: `Application/Features/{FeatureName}s/Commands/{Action}{FeatureName}/{Action}{FeatureName}Command.cs`
|
||||
- **Content**: An input model that implements MediatR's `IRequest<TResponse>`.
|
||||
|
||||
3. **Command / Query Handler**
|
||||
- **Path**: `Application/Features/{FeatureName}s/Commands/{Action}{FeatureName}/{Action}{FeatureName}CommandHandler.cs`
|
||||
- **Content**: Business logic processor that implements `IRequestHandler<{Action}{FeatureName}Command, TResponse>`. Inject any needed Repository or service here.
|
||||
|
||||
4. **WebAPI Controller**
|
||||
- **Path**: `WebAPI/Controllers/{FeatureName}sController.cs` (Remember to pluralize the Controller name if applicable).
|
||||
- **Content**: REST API endpoints. **Requirement:** Must receive `IMediator` via Dependency Injection in the constructor to dispatch requests (e.g., `await _mediator.Send(command)`).
|
||||
|
||||
## 2. Dependency Injection Configuration (NOT REQUIRED)
|
||||
|
||||
⚠️ **Note:** As per project standards, the CQRS flow **DOES NOT REQUIRE** updating Dependency Injection configuration files.
|
||||
|
||||
The MediatR library automatically scans and registers all Handlers inheriting from `IRequestHandler`. Therefore, you **ABSOLUTELY MUST SKIP** updating the DI config files for Handlers.
|
||||
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: GenerateNTierFeature
|
||||
description: Guide to generating an N-Tier architecture feature (including Entity, Interface, Service, Controller, and Dependency Injection configuration).
|
||||
---
|
||||
|
||||
# GenerateNTierFeature Skill
|
||||
|
||||
When a user requests to create a feature using the **N-Tier** flow, providing the **Feature Name** (e.g., `Category`), you **MUST** follow these steps to generate the corresponding code and files:
|
||||
|
||||
## 1. Directory and File Outputs
|
||||
|
||||
Create the following files with appropriate content for the {FeatureName}:
|
||||
|
||||
1. **Domain Entity**
|
||||
- **Path**: `Domain/Entities/{FeatureName}.cs`
|
||||
- **Content**: A basic Entity class defining the properties.
|
||||
|
||||
2. **Service Interface**
|
||||
- **Path**: `Application/Interfaces/I{FeatureName}Service.cs`
|
||||
- **Content**: Interfaces defining the method contracts for {FeatureName}.
|
||||
|
||||
3. **Service Implementation**
|
||||
- **Path**: `Application/Services/{FeatureName}Service.cs`
|
||||
- **Content**: A class that inherits from `I{FeatureName}Service`. **Requirement:** Use constructor Dependency Injection (DI) to receive instances (e.g., `IRepository<{FeatureName}>`).
|
||||
|
||||
4. **WebAPI Controller**
|
||||
- **Path**: `WebAPI/Controllers/{FeatureName}sController.cs` (Remember to pluralize the Controller name).
|
||||
- **Content**: The Controller class. **Requirement:** Must receive `I{FeatureName}Service` via constructor DI and define the corresponding endpoints.
|
||||
|
||||
## 2. Dependency Injection Configuration (MANDATORY STEP)
|
||||
|
||||
⚠️ **Important:** Unlike CQRS with MediatR mentioned above, the N-Tier flow **REQUIRES** you to manually register the newly created service into the IoC Container.
|
||||
|
||||
You **MUST** use the appropriate tool to open the project's DI configuration file (could be `DependencyInjection.cs` or `ServiceCollectionExtensions.cs` depending on the directory structure) and inject the following code block into the relevant service configuration method:
|
||||
|
||||
```csharp
|
||||
services.AddScoped<I{FeatureName}Service, {FeatureName}Service>();
|
||||
```
|
||||
|
||||
Make sure to use an accurate file editing tool (`replace_file_content` or `multi_replace_file_content`) to avoid breaking the DI file's syntax.
|
||||
Reference in New Issue
Block a user