
Clean Architecture
Layered architecture, CQRS, MediatR, repository pattern, separation of concerns, testability
1What is the Clean Architecture principle?
What is the Clean Architecture principle?
回答
Clean Architecture organizes code into concentric layers where dependencies point only inward (toward the domain). The Domain layer (entities, business rules) has no infrastructure dependencies. Outer layers (UI, Database, API) depend on domain abstractions via Dependency Inversion. This ensures testability, framework independence, and code maintainability.
2What are the main layers of Clean Architecture?
What are the main layers of Clean Architecture?
回答
Clean Architecture has 4 main layers: Domain (entities, business rules, repository interfaces), Application (use cases, DTOs, application logic), Infrastructure (repository implementations, DbContext, external services), and Presentation (API controllers, UI). Domain is at the center and depends on nothing. Application depends on Domain. Infrastructure and Presentation depend on Application and Domain.
3What is the CQRS pattern?
What is the CQRS pattern?
回答
CQRS (Command Query Responsibility Segregation) separates read (Queries) and write (Commands) operations. Commands modify state and return void or a simple result. Queries return data without modifying state. This separation allows independent optimization of reads (Dapper, SQL views) and writes (EF Core, DDD aggregates), and different scaling for each side.
What is the role of MediatR in Clean Architecture?
How to define a Command in MediatR?
+17 面接問題