command-handler

Implement MediatR command handlers with IUnitOfWork and ICommitEventService.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill command-handler
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: command-handler
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/microservice/command/command-handler
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill command-handler

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Implement MediatR command handlers for event-sourced microservices with clear patterns, validation, and per-feature boundaries.

Core Features & Use Cases

  • Create and update MediatR command handlers using primary constructor DI and IUnitOfWork.
  • Rebuild aggregates from history with LoadFromHistory and apply domain commands.
  • Commit new events deterministically via ICommitEventService, ensuring idempotency and proper event sourcing.
  • Follow feature-folder organization under Application/Features/Commands for maintainability and consistency.

Quick Start

Run a sample CreateOrder command through the MediatR pipeline to validate the handler flow.

Frequently Asked Questions about command-handler

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

FAQPage Schema
How do I implement MediatR command handlers for event-sourced microservices?

To implement MediatR command handlers for event-sourced microservices, use primary constructor dependency injection and IUnitOfWork to orchestrate commands. Rebuild aggregates from history using LoadFromHistory, then commit new events deterministically via ICommitEventService to ensure idempotency and proper event sourcing.

What is the best way to rebuild aggregates from event history in a command handler?

The best way to rebuild aggregates from event history in a command handler is using the LoadFromHistory method. Apply domain-specific command patterns to reconstruct aggregate state before validating and committing new events through ICommitEventService, ensuring reliable and idempotent workflows.

How do I ensure idempotency when committing events in a MediatR command handler?

To ensure idempotency when committing events in a MediatR command handler, use ICommitEventService to commit new events deterministically. Rebuild aggregates from history first, apply domain commands, then commit through the dedicated service to maintain reliable event sourcing workflows.

Does this command handler pattern work with domain-driven design and feature-folder organization?

Yes, this command handler pattern works with domain-driven design and feature-folder organization. Commands are structured under Application/Features/Commands folders, enforcing primary constructor DI, IUnitOfWork, and ICommitEventService usage for maintainable and consistent event-sourced microservices.

How do I structure create and update commands using MediatR and IUnitOfWork?

To structure create and update commands using MediatR and IUnitOfWork, use primary constructor dependency injection within feature-folder boundaries under Application/Features/Commands. Rebuild aggregates from history, apply domain commands, and commit events through ICommitEventService for reliable workflows.

Why does my event-sourced command handler need ICommitEventService alongside IUnitOfWork?

Your event-sourced command handler needs ICommitEventService alongside IUnitOfWork to commit new events deterministically. While IUnitOfWork manages transactional boundaries, ICommitEventService ensures proper event sourcing and idempotency when persisting new events after rebuilding aggregates from history.