How evgenirusev/.net-domain-driven-design-template works
Project Type and Purpose
• This is a monolithic .NET Core 8 solution using Clean Architecture and Domain-Driven Design (DDD) by grouping multiple bounded contexts into one deployable.
• It exposes several HTTP APIs (Web projects) and uses EF Core, MediatR, FluentValidation, AutoMapper and Scrutor under the hood.
File Structure
• Top‐level “bounded contexts” each have four layers:
• Application (commands, queries, DTOs, MediatR handlers)
• Domain (entities, value objects, domain events, interfaces)
• Infrastructure (EF Core DbContext, Repositories, Migrations, Services)
• Web (ASP.NET Core controllers, model binders, middleware, configuration)
• A shared “Common” context provides cross‐cutting abstractions (ICurrentUser, IImageService, base Entity, events dispatcher, validation behavior).
• ProjectStartup is the composition root (Program.cs, DI registrations, appsettings.json, migrations script).
Main Components
• Common Kernel
• Bounded Contexts:
• Identity
• ProductCatalog
• OrderManagement
• Statistics
• Startup Host
• Database(s) (single or per‐context)
• External HTTP call from OrderManagement → ProductCatalog
• Internal Event Bus (MediatR / IEventDispatcher) for Domain Events (OrderAddedEvent, ProductAddedEvent)
Relationships & Interactions
• Startup loads all Web API projects into one ASP.NET Core host and wires DI (via Scrutor’s assembly scanning).
• Web controllers call Application layer handlers (MediatR).
• Application handlers call Domain factories/repositories or Infrastructure services (e.g. IJwtGenerator, IImageService)
• Infrastructure persists aggregates via EF Core DbContexts.
• Upon saving aggregates, DomainEvents are raised, published by EventDispatcher, and handled by other contexts (e.g. Statistics.Application’s OrderAddedEventHandler).
• OrderManagement.Application uses IProductCatalogHttpService to fetch product info from the ProductCatalog Web API.
Architectural Patterns & Design Principles
• Vertical Slices: each feature (command/query) is self‐contained within its Application folder.
• Layered Clean Architecture: Web → Application → Domain → Infrastructure
• Bounded Context Isolation: contexts do not directly reference each other’s Domain or Infrastructure, only via Events or HTTP APIs.
• Shared Kernel: the Common project holds cross‐cutting abstractions.
• CQRS: separate Commands from Queries in Application layer.
• Anti-Corruption Layers: Factories for entity creation, Repositories for data access, FluentValidation for input validation, DomainEvents for cross‐context integration.
Technologies & Frameworks
• .NET Core 8 / ASP.NET Core 8
• Entity Framework Core 8
• MediatR for in‐process messaging
• FluentValidation for command/query validation
• AutoMapper for DTO ↔ Domain mapping
• Scrutor for DI registration
• xUnit & FluentAssertions for tests