Software Development

How do I implement the Clean Architecture pattern in a .NET Core 8 Web API project?

EL Asked by Elizabeth Reed · 05-03-2025
0 upvotes 18,341 views 0 comments
The question

I'm trying to move away from "Fat Controllers" and messy service layers. What is the standard project structure for Clean Architecture in the .NET world today? How do you properly separate the Domain, Application, Infrastructure, and Presentation layers while keeping Dependency Injection clean?

3 answers

0
ME
Answered on 25-04-2024

Clean Architecture is all about the "Dependency Rule"—dependencies only point inward. Your Domain layer (entities, specifications) is the core and has no dependencies. The Application layer (interfaces, DTOs, MediatR handlers) depends only on the Domain. The Infrastructure layer (EF Core, Email services, Cloud SDKs) implements those interfaces. Finally, the Presentation (Web API) is the entry point. A popular way to keep this clean in .NET is using the MediatR library for the CQRS pattern. This keeps your controllers extremely thin—usually just one line to send a command or query—making the whole system incredibly testable.

0
BR
Answered on 30-04-2025

Does this architecture add too much boilerplate for smaller projects? It feels like I'm creating four different classes just to save a single user record to a database.

RI 08-05-2025

Brandon, you’re absolutely right that it adds overhead. For a small "Internal Tool" or a simple CRUD app, Clean Architecture is definitely overkill. However, for an enterprise system that will live for 5+ years with a rotating team of developers, that "boilerplate" is what prevents the code from turning into spaghetti. It makes it much easier to swap out a SQL database for a NoSQL one, or change an email provider, without touching your core business logic. Choose the architecture based on the project's expected lifespan and complexity.

0
PA
Answered on 15-05-2025

I've found that using the "Vertical Slice" architecture is a great middle ground. It keeps all code for a single feature together, which reduces the constant jumping between projects.

EL 22-05-2025

Vertical Slicing is gaining a lot of traction lately! It definitely solves the "too many projects" frustration while still maintaining high cohesion and low coupling.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session