Engineering Insights

Clean Architecture in .NET 9: A Practical Guide

March 10, 2026 Eren Bağcı

Clean Architecture is not ceremony — it is insurance against the change you know is coming: new payment providers, new reporting rules, new mobile clients, new AI features bolted onto old domains.

Dependency Direction

Domain and application rules must not reference EF Core, ASP.NET, or HTTP. Infrastructure implements interfaces defined inward. Presentation composes use cases. When a framework upgrades or swaps, blast radius stays bounded.

.NET 9 Building Blocks

Minimal APIs for thin edges, source-generated DI for startup time, HybridCache for L2+L3 caching, and native AOT where latency budgets are tight. MediatR or custom mediators keep controllers from becoming 400-line god classes.

Testing Strategy

Unit-test domain invariants without a database. Integration-test repositories against Testcontainers SQL Server. Contract-test external APIs. Architecture tests (NetArchTest) enforce layer boundaries in CI.

When to Simplify

Not every CRUD admin screen needs CQRS. Start with clear modules, extract use cases when duplication hurts, and add event-driven patterns only when synchronous flows genuinely fail.