.NET Core Clean Architecture

.NET Clean Architecture usually combines dependency inversion, thin API controllers, application use cases, domain models, and infrastructure implementations.

Dependency Inversion

Depend on abstractions instead of concrete implementations.

Controller -> Application interface -> Infrastructure implementation

This keeps the application easier to test because dependencies can be mocked or replaced.

Common Project Shape

src/
  WebApi/
  Application/
  Domain/
  Infrastructure/

Web API

The API project handles HTTP concerns:

Keep controllers small. If a controller method starts making business decisions, move that behavior into the application layer.

Application

The application project contains use cases and contracts:

CQRS can be useful here when reads and writes have different shapes.

Domain

The domain project contains the core business model:

This layer should not know about ASP.NET Core, Entity Framework Core, or external APIs.

Infrastructure

The infrastructure project implements external details:

Source Notes