CQRS command pattern: command record + handler + validator using MediatR and FluentValidation. Three-section file organization.
From dotnet-ai-kitnpx claudepluginhub faysilalshareef/dotnet-ai-kit --plugin dotnet-ai-kitThis skill uses the workspace's default tool permissions.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Enables AI agents to execute x402 payments with per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents pay for APIs, services, or other agents.
namespace {Company}.{Domain}.Application.Features.Orders.Commands.Create;
public sealed record CreateOrderCommand(
string CustomerName,
decimal Total,
List<CreateOrderItemDto> Items) : IRequest<Result<Guid>>;
public sealed record CreateOrderItemDto(
string ProductName,
int Quantity,
decimal UnitPrice);
namespace {Company}.{Domain}.Application.Features.Orders.Commands.Create;
internal sealed class CreateOrderCommandValidator
: AbstractValidator<CreateOrderCommand>
{
public CreateOrderCommandValidator()
{
RuleFor(x => x.CustomerName)
.NotEmpty().WithMessage("Customer name is required")
.MaximumLength(200);
RuleFor(x => x.Total)
.GreaterThan(0).WithMessage("Total must be positive");
RuleFor(x => x.Items)
.NotEmpty().WithMessage("At least one item is required");
RuleForEach(x => x.Items).ChildRules(item =>
{
item.RuleFor(i => i.ProductName).NotEmpty();
item.RuleFor(i => i.Quantity).GreaterThan(0);
item.RuleFor(i => i.UnitPrice).GreaterThan(0);
});
}
}
namespace {Company}.{Domain}.Application.Features.Orders.Commands.Create;
internal sealed class CreateOrderCommandHandler(
IUnitOfWork unitOfWork)
: IRequestHandler<CreateOrderCommand, Result<Guid>>
{
public async Task<Result<Guid>> Handle(
CreateOrderCommand request, CancellationToken cancellationToken)
{
var order = Order.Create(
request.CustomerName,
request.Total,
request.Items.Select(i => new OrderItem(
i.ProductName, i.Quantity, i.UnitPrice)).ToList());
await unitOfWork.Orders.AddAsync(order, cancellationToken);
await unitOfWork.SaveChangesAsync(cancellationToken);
return Result<Guid>.Success(order.Id);
}
}
public sealed record UpdateOrderCommand(
Guid Id,
string CustomerName,
decimal Total) : IRequest<Result>;
internal sealed class UpdateOrderCommandHandler(
IUnitOfWork unitOfWork)
: IRequestHandler<UpdateOrderCommand, Result>
{
public async Task<Result> Handle(
UpdateOrderCommand request, CancellationToken cancellationToken)
{
var order = await unitOfWork.Orders.FindAsync(
request.Id, cancellationToken);
if (order is null)
return Result.Failure("Order not found");
order.Update(request.CustomerName, request.Total);
await unitOfWork.SaveChangesAsync(cancellationToken);
return Result.Success();
}
}
public sealed record DeleteOrderCommand(Guid Id) : IRequest<Result>;
internal sealed class DeleteOrderCommandHandler(
IUnitOfWork unitOfWork)
: IRequestHandler<DeleteOrderCommand, Result>
{
public async Task<Result> Handle(
DeleteOrderCommand request, CancellationToken cancellationToken)
{
var order = await unitOfWork.Orders.FindAsync(
request.Id, cancellationToken);
if (order is null)
return Result.Failure("Order not found");
unitOfWork.Orders.Remove(order);
await unitOfWork.SaveChangesAsync(cancellationToken);
return Result.Success();
}
}
Application/Features/Orders/Commands/
├── Create/
│ ├── CreateOrderCommand.cs
│ ├── CreateOrderCommandValidator.cs
│ └── CreateOrderCommandHandler.cs
├── Update/
│ ├── UpdateOrderCommand.cs
│ ├── UpdateOrderCommandValidator.cs
│ └── UpdateOrderCommandHandler.cs
└── Delete/
├── DeleteOrderCommand.cs
└── DeleteOrderCommandHandler.cs
| Anti-Pattern | Correct Approach |
|---|---|
| Command with mutable properties | Use sealed record (immutable) |
| Validation in handler | Use FluentValidation + pipeline behavior |
| Returning domain entity from handler | Return Result<T> with ID or DTO |
| Handler accessing DbContext directly | Use IUnitOfWork or IRepository |
grep -r "IRequest<\|IRequestHandler<" --include="*.cs"
grep -r "AbstractValidator<" --include="*.cs"
AddMediatR and AddValidatorsFromAssemblyValidationBehavior<,> pipeline behavior