Clean Architecture - amitbhilagude/userfullinks GitHub Wiki
Clean architecture overview
Solution contains 3 main projects. it is alternative for n-tier architecture
Core Project
Most of the business logic and domain model is implemented here
Infrastructure Project
DB connectivity and implementation is here
API or Web Project
Front-end application that contains endpoint and interacts with the core project. Controllers in this project are very small as all
business logic is reside in the Core project.
Earlier it was DB centric architecture not it is moved to the Domain centric architecture.
Principals
Separation of Concerns.
Separate code which has different responsibilities by creating folder or namespace etc.
Single Responsibility from SOLID i.e. Avoid God Classes which does everything
Don't repeat or duplications
Dependency Inversion: Should talk using abstractions using Interfaces.
Challenges with n-tier Architecture
This Architecture heavily depends on the DB layer and is difficult to test each layer separately.
Clean Architecture is Domain-Centric Design and Domain Model is the focus.
Domain Model vs Data Model
Data Model are EF Entities(Not DDD Entities) which fetches the Data in different views as per requirement
Domain Models are Entities(DDD Concept- Classes), Interfaces, Services and More
Rules
Domain Model should be part of Core Project
All Projects should depend on the Core Project
Innerproject should implement the Interface and the outer project should implement always e.g. Core project will have interfaces always.
Avoid direct dependency with Repository project except for Startup.cs and Integration test.
Core Project shouldn't have dependencies except Standerd Nuget packages.It contains Interfaces, DDD Concepts(Entities, Value Objects, Aggregates, Domain Services and exceptions), Domain Events and Event Handlers.It uses Specification Pattern. Query-based pattern to communicate to repository pattern or Core Project
Infrastructure Project: It contents Repositories, EF Core context, Cached Repository, HTTP Clients, Email send or any other interfaces which is used by internal Infrastructure project e.g. Blob Interface to connect to blob storage. It needs to loosely-coupled pattern which can be replaced easily by any other.
Web Project: Controllers, Views, Razor pages, View Models, Filters, etc. or any interfaces used inside.
Controller needs to be as light as possible. you can interact controller with the core by using domain events. MediatR is a common NuGet package is sued to send domain events.