Setting aside the project sprawl that gave Clean Architecture its bad name, this piece builds a small ASP.NET Core solution around a single rule: source dependencies point inward, with four projects and small handlers. It shows which pieces of the pattern a developer can safely drop.
Key points
- The dependency rule reduces to one sentence: source dependencies point inward, and outer layers implement ports the inner layers declare.
- Four projects are enough — Domain, Application, Infrastructure and Api — with Application declaring the ports it needs, such as IInquiryRepository and IEmailSender.
- Each use case becomes a small handler; the sample uses SubmitInquiryCommand with ICommandHandler<,>.
- Validation runs as a pipeline step before the handler, so the handler only ever sees valid input.
- Expected failures return a single Result type instead of exceptions, treating 'not found' and 'validation failed' as normal outcomes.
- Tests split into millisecond unit tests with fake ports and integration tests that drive real endpoints and EF mappings via WebApplicationFactory and SQLite.
Why it matters
This article answers the objection teams actually raise: the problem is not the architecture but the number of files added to protect the rule. For a developer maintaining a small or mid-sized ASP.NET Core service, the practical takeaway is that a testable structure does not require a repository per table or a generic IRepository<T> — read screens can be served by read-model queries in Infrastructure while the write side stays on aggregates that carry rules.
Before adopting it, look at your own solution. Declaring ports in Application buys handlers that never touch EF Core and unit tests that run fast, but a record and handler per command can produce needless files for trivial CRUD endpoints. Agree as a team on where validation lives and keep the Result type from coexisting with exception-based flow in the same endpoint, or you will end up maintaining both styles side by side. If your team already runs MediatR-style pipelines, this is a smaller footprint rather than a rewrite.
Real-world use
- Writing a read-model query in Infrastructure for a single-screen read instead of opening a repository per table
- Keeping repositories for aggregates that carry rules, such as an Inquiry, and leaving simple CRUD tables alone
- Isolating infrastructure decisions — swapping SMTP providers, or SQLite instead of SQL Server in tests — behind one class
- Using WebApplicationFactory with SQLite to exercise real endpoints and EF mappings in integration tests
This summary was generated by the agent from the original post on DEV Community: #aspnetcore. The full text and all rights belong to its author and publisher. Go to original