一键导入
source-command-new-handler
Scaffold a new MediatR command or query handler (request + handler + validator + DTO + tests) following project CQRS conventions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Scaffold a new MediatR command or query handler (request + handler + validator + DTO + tests) following project CQRS conventions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Run the canonical build plus all nine per-project test commands from docs/TESTING.md. Never uses solution-level dotnet test.
Create or re-baseline lean, repository-grounded implementation plans and persistent dev docs when users ask for an implementation plan, technical plan, feature plan, refactor plan, or dev-docs workstream.
Senior CTO review workflow for repository-grounded implementation-plan workstreams used before coding.
Apply project EF Core conventions for repositories, DbContext setup, query filters, migrations, and seeded lookup data.
Create a self-contained HTML artifact focused on a high-quality SVG architecture or system diagram with minimal supporting prose.
Create a pragmatic self-contained HTML plan that organizes the user's plan content visually without expanding the scope unnecessarily.
| name | source-command-new-handler |
| description | Scaffold a new MediatR command or query handler (request + handler + validator + DTO + tests) following project CQRS conventions. |
Use this skill when the user asks to run the migrated source command new-handler.
Primary references:
| Question | Command | Query |
|---|---|---|
| Mutates state? | ✔ | ✘ |
| Returns data? | May return an ID or minimal result | Always returns a DTO |
| Auth default | [Authorize] | [AllowAnonymous] by default |
| Response type | BaseCommandResponse<Guid> (or bool for some deletes) | DTO or PaginatedResult<TDto> |
| Cache interaction | RemoveAsync() | GetOrCreateAsync() |
If the change mixes read and write, split into two handlers.
All paths are relative to Explore.Application/Features/{FeatureArea}/:
Commands/
Create{Resource}/
Create{Resource}Command.cs # IRequest<BaseCommandResponse<Guid>>
Create{Resource}CommandHandler.cs # : IRequestHandler<...>
Create{Resource}CommandValidator.cs # : AbstractValidator<...> — manual ctor call
Create{Resource}Dto.cs # input DTO (wrapped by Command)
Queries/
Get{Resource}/
Get{Resource}Request.cs # IRequest<{Resource}Dto> (or PaginatedResult<...>)
Get{Resource}RequestHandler.cs # : IRequestHandler<...>
Get{Resource}Dto.cs # projection
Explore.API/Controllers/{Resource}Controller.cs)[HttpGet("{id:guid}", Name = RouteNames.{Resource}Get)]
[AllowAnonymous]
[EndpointClassification(EndpointClass.Public)]
[ProducesResponseType<{Resource}Dto>(StatusCodes.Status200OK)]
public async Task<IActionResult> Get(Guid id, CancellationToken ct)
=> this.AsActionResult(await mediator.Send(new Get{Resource}Request(id), ct));
Explore.Application).new Create{Resource}CommandValidator().ValidateAsync(request, ct).CancellationToken through every async call.IUnitOfWork.ExecuteInTransactionAsync.BaseCommandResponse.Errors, do not throw.AsNoTracking() via repository / Specification Pattern.HybridCache.GetOrCreateAsync(key, factory, ct).HybridCache.RemoveAsync(key, ct) after commit.Required minimum:
Event.Application.UnitTests/Features/{FeatureArea}/ covering:
Event.API.IntegrationTests/Controllers/{Resource}ControllerTests.cs covering:
add-hal-link intent).If the resource is exposed with HAL links, add / update:
Explore.API/Hateoas/Policies/{Resource}LinkPolicy.cs — separate policies for detail and collection.yield return in policies. Do not inline conditions in the controller.See .claude/rules/api-hateoas.md.
[Authorize] and implement IAuthorizedRequest OR decorate the request with [AuthorizeResource].ISecureRequest.AuthorizationException → 403 via chained IExceptionHandler.See .agents/skills/auth-patterns/SKILL.md.
DbContext directly in the handler (use repository).CancellationToken.BaseCommandResponse<> on writes.@page (Blazor) and controller without reconciliation.After scaffolding, run:
dotnet build --configuration Release --verbosity quiet
dotnet test --project Event.Application.UnitTests/Event.Application.UnitTests.csproj --configuration Release --verbosity quiet
dotnet test --project Event.Architecture.Tests/Event.Architecture.Tests.csproj --configuration Release --verbosity quiet
dotnet test --project Event.API.IntegrationTests/Event.API.IntegrationTests.csproj --configuration Release --verbosity quiet
AGENTS.md — cold-start flow./check/review-pradd-cqrs-handleradd-write-endpointadd-get-endpoint