Clean architecture in mvc and web api combine using dapper with folder structure
To combine Clean Architecture in both ASP.NET Core MVC and Web API using Dapper with a clean
and organized folder structure, the structure should reflect the separation of concerns. Here's how
you can structure the solution:
Solution Structure Overview
src/
|-- Presentation/
| |-- WebApi/
| | |-- Controllers/
| | |-- Models/
| | |-- Views/
| |-- MvcApp/
| |-- Controllers/
| |-- Models/
| |-- Views/
|-- Application/
| |-- DTOs/
| |-- Interfaces/
| |-- Services/
|-- Domain/
| |-- Entities/
| |-- Interfaces/
|-- Infrastructure/
| |-- Persistence/
| |-- Repositories/
| |-- Data/
|
tests/
|-- UnitTests/
| |-- Application/
| |-- Domain/
| |-- Infrastructure/
Summary
This folder structure respects Clean Architecture principles by separating each layer (Presentation,
Application, Domain, Infrastructure) while also allowing for flexibility in how both MVC and Web API
applications are developed. Both projects can leverage the same business logic and data access
code, while being decoupled from specific implementation details like Dapper.