How eriksena16/simplecqrsapiwithmediatr works
Project type and purpose
• This is a backend API service built with ASP.NET Core.
• It demonstrates Domain-Driven Design (DDD) layered architecture combined with CQRS and MediatR for message dispatching.
File structure
• Top-level solution: SimpleCQRSApi.sln
• Four main folders under src/:
1. Simple.API
– Controllers (SalesController.cs)
– Configuration (appsettings.json, launchSettings.json)
– HTTP client file (Simple.API.http)
2. Simple.Application
– Commands & Queries (CreateSaleCommand.cs, etc.)
– DTOs (Request/Response)
– Handlers (CreateSaleCommandHandler, …)
3. Simple.Domain
– Entities (Sale, SaleItem)
– Interfaces (Repositories, Services)
4. Simple.Infrastructure
– EF Core DbContext (AppDbContext)
– Repository implementations
– Domain service implementations (OrderProcessor)
README
• Confirms the four‐layer DDD approach: API, Application, Domain, Infrastructure
• Mentions use of MediatR for decoupling, and CQRS to separate reads and writes.
Components and interactions
• API Layer (ASP.NET Core Web API)
• MediatR (in-process message bus)
• Application Layer (Commands, Queries, Handlers)
• Domain Layer (Entities, Interfaces)
• Infrastructure Layer (EF Core DbContext, Repositories, Services)
• Database (e.g., SQL Server)
1. Client → HTTP Request → API Controller
2. Controller → sends Command/Query to MediatR
3. MediatR → dispatches to appropriate Handler in Application
4. Handler → invokes Domain Entities and Domain Services via interfaces
5. Handler → calls Repository interface → implemented by Infrastructure → interacts with DbContext
6. DbContext → reads/writes Database
7. Handler returns DTO → MediatR → Controller → HTTP Response → Client
c. Architectural patterns & principles:
• Layered Architecture (separate folders per layer)
• CQRS (Commands vs. Queries)
• MediatR for decoupled in‐process messaging
• Dependency Inversion (Domain interfaces → Infrastructure implementations)
• Repository Pattern via EF Core
d. Key technologies & frameworks:
• ASP.NET Core Web API
• MediatR
• Entity Framework Core
• SQL Server (or any relational DB)
• .NET 6+
Detail level
• Four projects as separate blocks.
• Within each block, optionally note subcomponents (Controllers, Handlers, Entities).