How hernaski/domain-driven-design-solution works
Main Project Components
• Domain Layer (MySolution.Domain): This contains the main business entities (Category.cs, Product.cs) and interfaces (both for repositories and services) without any dependency on concrete implementations.
• Infrastructure Layer (MySolution.Infrastructure): Here you find the EF Core database context (MyDatabaseContext.cs), Fluent API configurations (CategoryFluent.cs, ProductFluent.cs) and repository implementations. This layer contains the actual data access logic and is isolated from the Domain.
• Services Layer (MySolution.Services): This layer holds the application/business logic implementations (e.g. CategoryServices.cs, ProductServices.cs) that consume the Domain interfaces.
• IoC (Dependency Injection) Project (MySolution.Ioc): This project is responsible for configuring and enforcing dependency injection. It makes use of PrivateAssets in its project references to ensure that concrete implementations (from Services and Infrastructure) are hidden from the presentation layer.
• Presentation Layer (MySolution.Web.Api): This is your Web API project with controllers, DTOs, and configuration files (e.g. Startup.cs, Program.cs) that expose endpoints for external users or systems. It references only Domain and IoC, ensuring that the core logic remains decoupled from the presentation.
Diagramming the Relationships and Interactions
• Domain (Entities and Interfaces)
• Infrastructure (Data Access: Context, Fluent APIs, Repository Implementations)
• Services (Business/Application Logic)
• IoC/Dependency Injection (Service registration and configuration)
• Web API (Controllers, DTOs, API Configuration)
• The Web API layer depends on Domain for its entity and interface definitions and on IoC for dependency injection configuration.
• The IoC project wires up the Services and Infrastructure components by mapping Domain interfaces to their concrete implementations in these layers.
• Services depend on Domain (for interfaces/data contracts) and are registered via IoC; likewise, Infrastructure’s repositories implement the interfaces declared in Domain.
• Optionally, illustrate data flow from Web API controllers to Services to Infrastructure and back, highlighting that changes in UI (presentation) do not affect the Domain.
Highlighting Architectural Patterns and Principles
• Domain Driven Design (DDD): Emphasize that the Domain layer is the core of the solution and contains only the business rules and entities.
• Separation of Concerns: Display that the Domain, Services, Infrastructure, and Presentation layers are independent, reducing coupling.
• Dependency Injection / Inversion of Control: Highlight the IoC project configuration where concrete implementations are injected based on domain interfaces.
• Use of Fluent API for mapping entity behaviors in the Infrastructure layer (instead of Data Annotations), making the domain purely business-oriented.
Including Specific Technologies and Frameworks
• That the solution is built with .NET 5 and uses Entity Framework Core 5 for ORM.
• Swagger configuration exists in the Web API project for API documentation.
Essential Elements
• “Services”: with the business logic classes.
• “IoC/Dependency Injection”: showing how the services and repositories are wired.
• “Web API”: with controllers, DTOs, and configuration.
• Implementation layers (Infrastructure and Services) in another.
• Annotations for key patterns (DDD, DI), technologies (.NET 5, EF Core 5, Swagger) beside the respective components.