create-cqrs-handler

Scaffolds CQRS command handlers with commands, result types, and DI registration in .NET.

Updated Nov 19, 2020
One-click install
npx skills add https://github.com/kwojtasinski-repo/ECommerceApp --skill create-cqrs-handler-kwojtasinski-repo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-cqrs-handler
Source: https://github.com/kwojtasinski-repo/ECommerceApp/tree/main/.github/skills/create-cqrs-handler
Command: npx skills add https://github.com/kwojtasinski-repo/ECommerceApp --skill create-cqrs-handler-kwojtasinski-repo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Manually creating CQRS command handlers across bounded contexts involves repetitive boilerplate and risks inconsistent patterns. This Skill generates the complete set of files—command record, result type, handler class, and DI registration—following the project's established sealed record and static factory conventions. ## Core Features & Use Cases - Full Handler Scaffolding: Creates the ICommandHandler interface (first use only), command record, result type, handler class, and DI registration line in one workflow. - Flexible Result Types: Supports enum results for simple state outcomes and sealed records with static factories for rich outcomes carrying data like entity IDs. - Convention Enforcement: Ensures handlers are internal sealed, commands are immutable sealed records, and business logic stays out of records and results. - Use Case: When adding a new CancelOrder operation to the Sales/Orders bounded context, generate the command, result, handler, and registration in seconds instead of hand-writing four files. ## Quick Start Ask the AI to create a CQRS command handler named CancelOrder in the Sales/Orders bounded context with an enum result type.

Frequently Asked Questions about create-cqrs-handler

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a CQRS command handler in .NET?

Define a sealed record for the command, create a result type, then implement an internal sealed handler class implementing ICommandHandler<TCommand, TResult>. Register it with AddScoped in the bounded context's Extensions.cs file.

Should a CQRS command result be an enum or a record?

Use an enum when the operation succeeds or fails with distinct named states and the caller routes on the state. Use a sealed record with static factory methods when the result carries data like a created entity ID or detailed failure reasons.

What is the difference between ICommandHandler and IMessageHandler?

ICommandHandler<TCommand, TResult> handles intra-BC commands that return a typed result to the caller. IMessageHandler<T> processes cross-bounded-context events and is a separate pattern that should not be confused with command handling.

Where should validation logic go in a CQRS command?

Validation does not belong in the command record, which stays an immutable sealed record with no logic. Use a separate FluentValidation validator for input validation, and keep business rules inside the handler or domain layer.

When should a handler throw exceptions instead of returning a result?

Handlers return result types for expected failures like NotFound, letting callers branch on the outcome. Throw BusinessException only for programming errors or invariant violations, never for normal domain failure cases.