Skip to content
CØDE N!NJΔ edited this page Jun 19, 2025 · 6 revisions

Core Components:

1. Event Infrastructure

IEvent interface and BaseEvent record for all events EventStoreEntry for persistence Type-safe event definitions using records

2. Aggregate Root Pattern

Base AggregateRoot class with event sourcing capabilities Uncommitted events tracking Version-based optimistic concurrency control Event application for state reconstruction

3. Event Store

IEventStore interface for pluggable storage In-memory implementation with concurrency control Event serialization/deserialization Stream-based event organization

4. Repository Pattern

Generic IRepository interface Event-sourced repository implementation Automatic aggregate reconstruction from events

Domain Implementation:

  1. Bank Account Aggregate

Rich domain model with business rules Event-driven state changes Factory methods for aggregate creation Proper encapsulation and validation

6. Domain Events

Strongly-typed events using records Immutable event data Clear event naming conventions

Application Layer:

  1. Application Services

Command handling with business logic Transaction boundaries Error handling and validation

  1. Projections/Read Models

Separate read model for queries Event handlers for projection updates CQRS pattern implementation

Key Features:

Immutable Events: All events are immutable records Optimistic Concurrency: Version-based conflict detection Event Replay: Complete state reconstruction from events Type Safety: Strong typing throughout the system Testability: Easy to unit test with in-memory implementations Separation of Concerns: Clean architecture with distinct layers

Usage: The demo shows creating accounts, performing transactions, viewing event history, and maintaining projections. This foundation can be extended with:

Persistent event stores (SQL Server, PostgreSQL, EventStore DB) Snapshotting for performance Event publishing for integration Saga patterns for long-running processes Multiple bounded contexts

This implementation provides a solid foundation for building event-sourced systems in .NET!

Clone this wiki locally