Explain clean architecture in .NET and identify signs that the abstraction layers have become unnecessary ceremony.
Zomato · Full Stack Developer · 3-4-years · technical
Published
Year not specified · .NET, Software Engineering, System Design
Community answers
Posted by wasAsked editorial collection
Clean Architecture keeps business rules independent of delivery and infrastructure details. Dependencies point inward: the domain knows no database or web framework; application use cases define ports; infrastructure implements them; the API composes the system.
Example:
public interface IOrderRepository {
Task<Order?> GetAsync(OrderId id, CancellationToken ct);
}
The interface should reflect a domain need, not mirror every ORM method. Keep controllers thin, place transaction boundaries around use cases, and map transport DTOs at the edge. Avoid creating layers that merely forward calls. Architecture is successful when important rules are testable without a server/database and infrastructure can change without rewriting the domain.
Backbencher Developer · · 0 likes
Clean Architecture organises code in concentric layers with dependencies pointing inward:
- Domain: entities, value objects and business rules. No dependencies on frameworks.
- Application: use cases (commands, queries, services) and interfaces for what they need (repositories, email, clock).
- Infrastructure: implementations — EF Core, external APIs, file storage, messaging.
- Presentation: ASP.NET Core controllers or minimal APIs, mapping HTTP to use cases.
The Dependency Rule says inner layers know nothing about outer layers. Benefits: business logic can be tested without a database or web server, and infrastructure can change without touching rules.
Signs the layers have become ceremony:
- Every feature touches six or more files: controller, command, handler, validator, DTO, mapper, repository interface and implementation — for simple CRUD with no real logic.
- Interfaces with exactly one implementation that is never replaced or mocked (IUserService implemented only by UserService).
- A generic repository wrapping EF Core's DbSet, which already is a repository and unit of work, while hiding useful features like Include and projections.
- Mappers that copy identical objects field by field between layers.
- An anaemic domain: entities are bags of properties and the "domain layer" holds no rules.
- Simple changes take much longer than the business complexity justifies, and new developers struggle to find where things happen.
Pragmatic responses:
- Use vertical slice architecture for simple features: keep request, handler and data access together in one feature folder.
- Let the application layer use DbContext directly where abstraction adds no value, while keeping real domain logic in the domain.
- Introduce abstractions where there is a real reason: multiple implementations, external services that must be faked in tests, or volatile infrastructure.
- Apply the full layering only to the complex core of the system.
The goal is maintainability, not a particular folder structure.