How vinh-dev/cleanarchitecture works
Main components
• Core – This is where your domain logic lives. It contains entities, aggregates, domain events, DTOs, interfaces, and event handlers. It is the heart of your “business rules” and DDD logic.
• SharedKernel – Contains common cross-cutting elements like base classes and interfaces shared across bounded contexts.
• Infrastructure – Implements external concerns such as data access, email sending (both Fake and SMTP options), and configuration for the Entity Framework Core. Note the separate folders for the data models, EF repository, and startup dependency injection “wiring” (via Autofac as mentioned).
• Web – An ASP.NET Core project that functions as the system’s presentation layer. It contains both API controllers (with endpoints organized by contributors and projects) and traditional MVC controllers/views. It also handles configuration (appsettings.json) and serves static assets (wwwroot).
• Tests – Organized into Unit, Functional, and Integration test projects. They validate the behavior of the Core, Infrastructure, and Web components.
Relationships and interactions
• The Web layer (UI/API) depends on and communicates with the Core for business logic.
• The Infrastructure layer implements interfaces defined in Core (repository, email sending, etc.) and is wired into the application during setup (via the StartupSetup.cs file in Infrastructure).
• The SharedKernel provides common definitions that both Core and Infrastructure reference.
• Domain events in Core trigger handlers that are implemented across various layers (often in Core or Infrastructure), decoupling interactions.
• The Test projects simulate interactions among these components to ensure quality.
Architectural patterns/design principles
• Clean Architecture / Onion Architecture (also sometimes known as hexagonal or ports-and-adapters) is fundamental here. The core remains independent of outer concerns.
• Domain Events are used to decouple entity actions (e.g., marking a ToDo item as complete) from side-effect processing (e.g., email notification).
Technologies and frameworks
• ASP.NET Core, Entity Framework Core (with usage of EF migrations and configurations), Autofac for dependency injection, and testing frameworks such as xUnit and Moq.
• The project also uses .NET Core SDK command line template features for project structure generation.
• Use clear, descriptive labels for each component and layer (e.g., “Core – Domain Logic”, “Infrastructure – Data Access”, “Web – API & UI”).
• Web → Core (calls business operations)
• Core → Infrastructure (invokes repository methods, email sending)
• Domain events dispatched within Core → Handlers in Core/Infrastructure