aggregate-design

Design event-sourced aggregate roots for .NET command microservices.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill captures proven patterns and guardrails for designing and implementing event-sourced aggregate roots in .NET command microservices, preventing common mistakes like public setters, constructor-based creation, and incorrect sequence handling.

Core Features & Use Cases

  • Aggregate base pattern: guidance for a generic Aggregate<T> base that uses dynamic dispatch to route events to typed Apply overloads.
  • Event lifecycle rules: best practices for ApplyChange semantics, sequence validation, setting aggregate Id on the first event, and tracking uncommitted events for persistence.
  • Creation and replay: patterns for factory-based aggregate creation, LoadFromHistory replay without marking events as new, and committing new events via a commit service.
  • Anti-patterns and detection: lists common anti-patterns and search commands to detect existing implementations and integration steps to add aggregates to a project.
  • Use cases: creating new domain entities, adding behaviors to existing aggregates, and enforcing domain invariants inside aggregate methods.

Quick Start

Ask the AI to design an Order aggregate implementing event sourcing with factory creation, typed Apply handlers, LoadFromHistory replay, sequence validation, and uncommitted event tracking for your .NET command microservice.

Frequently Asked Questions about aggregate-design

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

FAQPage Schema
How do I implement an event-sourced aggregate root in a .NET command microservice?

To implement an event-sourced aggregate root in .NET, use factory-based creation, private state setters, and typed Apply handlers. Route events using dynamic dispatch, validate event sequences, and track uncommitted events for persistence via a commit service.

What is the correct way to replay event history in a .NET aggregate without registering new events?

Replay event history using a LoadFromHistory method that applies past events without marking them as new. This ensures historical state reconstruction remains separate from tracking uncommitted events meant for the commit service workflow.

Why should aggregate state use private setters instead of public properties in event sourcing?

Aggregate state uses private setters in event sourcing to enforce domain invariants and prevent external mutation. State changes must only occur through typed Apply handlers triggered by events, avoiding common anti-patterns like public setters or constructor-based creation.

How does dynamic dispatch route events to typed Apply handlers in a generic aggregate base class?

Dynamic dispatch routes events to typed Apply handlers by using reflection or a dynamic method to match the event type at runtime. A generic Aggregate<T> base class applies this mechanism to automatically invoke the correct overload for each specific domain event.

Can I use CQRS and DDD patterns alongside event-sourced aggregates in .NET?

You can use CQRS and DDD patterns with event-sourced aggregates in .NET. The aggregate design supports these patterns by encapsulating domain logic, enforcing invariants inside aggregate methods, and separating command handling from event persistence workflows.

What sequence validation rules are needed when committing events from a .NET aggregate?

Sequence validation rules for committing events require setting the aggregate Id on the first event and ensuring correct chronological ordering. The aggregate must validate sequences during ApplyChange operations before tracking and forwarding events to the commit service.