Clean architecture in .NET is a way of organizing a codebase so that business rules sit at the center and everything fragile—databases, web frameworks, UI, third-party SDKs—sits at the edge. The one non-negotiable condition is the dependency rule: source-code dependencies point inward only. Inner layers know nothing about outer layers. In .NET terms, your domain project shouldn't reference Entity Framework Core, ASP.NET Core, or a message broker package; those reference it instead. That single constraint is what makes the pattern valuable, and it's also what makes it expensive if you apply it indiscriminately. The rest of this article unpacks what the layers actually contain, how a real request flows through them, where teams get it wrong, and when a simpler layout beats it.

The dependency rule is the whole idea

Most architectural discussions about .NET drift into folder names and project counts. Those are consequences, not the concept. The concept is directionality.

Picture concentric rings. The innermost ring holds entities and domain rules. The next ring holds application use cases. Further out sit interface adapters—controllers, presenters, repository implementations, gRPC endpoints. At the outermost edge sit frameworks and drivers: the ASP.NET Core host, EF Core's DbContext, Dapper, Redis clients, SMTP libraries, cloud SDKs.

The rule says an inner ring may never name a type from an outer ring. Not in a using statement, not in a method signature, not in a generic parameter. When the domain needs to send an email or persist an order, it declares an abstraction it owns—say an IEmailSender or IOrderRepository interface—and an outer ring supplies the implementation. This is the Dependency Inversion Principle applied at project scale, and it's why the pattern is sometimes described as "screaming architecture" or a "ports and adapters" arrangement: the core defines ports, the edges plug in adapters.

Why bother? Three concrete payoffs. First, business rules become testable without a database, a web server, or a container—you instantiate plain objects and assert. Second, swapping infrastructure (moving from SQL Server to PostgreSQL, from REST to messaging) touches adapters, not logic. Third, the compiler enforces the boundary: if someone on the team tries to call DbContext.SaveChanges() from inside a domain entity, the build fails. That's a much stronger guarantee than a wiki page asking people to be careful.

The rule cuts both ways in practice. Inner layers must not leak framework types into their public surface either. An entity method that returns IActionResult, or a use case that accepts a HttpContext, has broken the rule even though no project reference changed. Watch for that.

What each layer actually holds

Layer contents vary by team, but the mainstream .NET arrangement (popularized by Jason Taylor's and Ardalis's templates, and consistent with the original Clean Architecture formulation) looks like this.

Domain. Entities, value objects, domain events, enums, domain exceptions, and specification or policy classes that encode invariants. No base classes from Microsoft.EntityFrameworkCore, no attributes from System.ComponentModel.DataAnnotations if you want to keep validation where it belongs. A Money value object, an Order aggregate that refuses to add a line after shipment, a DiscountPolicy—these live here. Pure C#, ideally zero NuGet dependencies beyond maybe a primitives package.

Application. Use cases. In modern .NET this is usually a MediatR-style handler per command or query, plus DTOs, validation, mapping profiles, and the interfaces the infrastructure will implement (IOrderRepository, IEmailSender, IDateTimeProvider). It references Domain. It may reference a lightweight abstraction package, but not EF Core or ASP.NET Core. This layer answers "what operations does the system support and in what order do the steps run," without caring how persistence or transport works.

Infrastructure. EF Core DbContext, entity configurations, migrations, repository implementations, external API clients, file storage, email senders, caching. References Application (to implement its interfaces) and Domain. This is where framework-specific code is welcome.

Presentation (or Web/API). Controllers, minimal API endpoints, filters, middleware, authentication wiring, DI composition root. References Application and, for DI registration, Infrastructure. In many templates the composition root is a separate Host or Web project so Infrastructure isn't referenced by the API project directly—a refinement worth adopting as the system grows.

Two practical notes. First, the number of projects is a style choice, not a requirement. You can enforce the same dependency direction with a single project using namespaces and an architecture test (NetArchTest or ArchUnitNET can assert "Domain must not depend on Infrastructure"). Multiple projects make violations impossible to compile, which is a stronger enforcement mechanism, but they add solution friction. Second, keep DTOs in Application, not Domain. Domain types shouldn't be serialization contracts.

How a request flows through the layers

Tracing one request makes the abstraction concrete. Suppose a customer places an order via POST /orders.

1: The endpoint in the presentation layer binds the request body to a command DTO and hands it to the mediator or directly to an application service. 2: The application handler loads the aggregate through IOrderRepository, which is just an interface at this point. 3: The handler invokes domain behavior—order.AddLine(product, quantity)—and the entity enforces invariants, throwing a domain exception if the quantity exceeds stock policy. 4: The handler asks a domain service or policy for pricing and applies it. 5: The handler calls IOrderRepository.Add(order) and IUnitOfWork.SaveChangesAsync(). 6: An infrastructure class, wired via DI, implements the repository using EF Core and writes to SQL Server. 7: A domain event raised in step 3 is dispatched—by an interceptor in infrastructure or a behavior in the pipeline—to send a confirmation email through IEmailSender.

Notice what the handler never mentions: HTTP status codes, SQL, connection strings, or the mail provider. That's the payoff in miniature. The handler is a plain class with constructor-injected interfaces; a unit test can pass fakes for all three and assert the order moved to the correct state.

Here's the shape of the interface the application layer owns and infrastructure implements:

The AppDbContext type appears only on the right side. If you find DbContext in a handler signature, the boundary has leaked.

Keeping the core honest: validation, mapping, and cross-cutting concerns

Clean architecture doesn't stop at project references; the daily discipline is in the details.

Validation splits into two kinds. Input validation (is the email well-formed, is the quantity positive) belongs in the application layer, typically via FluentValidation in a pipeline behavior. Business invariants (can't ship an unpaid order) belong in the domain and should throw domain exceptions that a middleware translates to problem details or a 422. Mixing them—using data annotations on entities and a ModelState check in a controller—quietly couples the domain to ASP.NET Core.

Mapping. Manual mapping methods are fine and fast. AutoMapper is common in templates but has fallen out of favor in some teams because of runtime failures and debugging friction; source-generated mappers (Mapperly) are a middle ground. Whichever you pick, the domain should never carry attributes purely for serialization.

Cross-cutting concerns. Logging, transactions, retries, and authorization checks usually fit naturally as MediatR pipeline behaviors or middleware in the outer layers. Don't smuggle an ILogger into a domain entity—log in the handler or an infrastructure decorator. If a domain rule genuinely needs to record something observable, raise a domain event and let the edge handle it.

Time and randomness. DateTime.UtcNow and Guid.NewGuid() inside domain code make tests flaky. Inject IDateTimeProvider and an ID generator from the application layer. It's a small interface with a big testability payoff.

A subtle failure case: repositories that return IQueryable. That hands EF Core's query provider to the application layer and lets LINQ-to-SQL leaks (provider-specific translations, N+1 surprises) creep inward. Prefer methods that return materialized results or explicit specifications.

A minimal sketch of the wiring

Composition root in the web project:

AddApplication registers handlers from the Application assembly; AddInfrastructure registers AppDbContext with UseSqlServer, repository implementations, and adapters. The web project is the only place that knows the connection string. That's the intended asymmetry: the host is the assembly point, and everything else is a library.

Trade-offs: where clean architecture costs you

The pattern is not free, and pretending otherwise is how teams end up with cargo-cult folders and a bloated solution.

Ceremony and indirection. Every feature now has a command, a handler, a repository method, a DTO, a mapping, and sometimes a validator. For a CRUD screen with no invariants, that's four files where one minimal API endpoint with db.Todos.Add would do. The indirection pays off when rules are complex or the system is long-lived; it's a tax when the system is a thin data gateway.

Over-abstraction. Teams often wrap IRepository around DbSet and end up with an abstraction that duplicates EF Core without adding meaning. A repository should express domain-level queries (GetOverdueInvoices, FindByCustomerAndStatus), not generic CRUD. If your repository interface has GetAll() and Update(), you've reimplemented EF poorly.

Anemic domain model. Clean architecture's emphasis on use cases tempts teams to put all logic in handlers and leave entities as property bags. That's not a failure of the pattern—it's a failure to use the inner ring. Rich entities plus thin handlers is the goal.

Performance and query friction. Loading a full aggregate to change one field, or fighting EF Core's tracking from behind an interface, can slow things down. High-throughput read paths often bypass the pattern with dedicated query handlers using Dapper or raw SQL in infrastructure—legitimate, and worth designing for explicitly rather than discovering late.

Learning curve and hiring. New developers need to understand the direction rule and the DI graph before they can ship. That's a real onboarding cost, especially on small teams.

A fair comparison is a vertical-slice or "feature folder" layout: organize by use case (Orders/CreateOrder/…), allow direct EF Core access in the handler, and use a shared kernel for domain types. It's far lighter for CRUD-heavy apps and scales well for many products. Clean architecture wins when the domain is genuinely complex, when you need to test rules in isolation, or when infrastructure choices are likely to change. It loses when the app is mostly forms over data.

When to choose it, and what to watch

Choose clean architecture when: the business rules are the hard part of the product (billing, scheduling, pricing, workflow); you expect to swap databases, transports, or third-party services; you have multiple entry points (web, background jobs, CLI, gRPC) over the same logic; or compliance and testability demand that rules be provable without infrastructure.

Don't choose it when: the system is a thin proxy over an API or a single-tenant admin tool with trivial rules; the team is small and the product may pivot; or the deadline is too short to absorb the structure's overhead. You can start with a vertical-slice or layered layout and extract a proper domain later—refactoring toward clean architecture is much cheaper than the reverse.

Practical guards to put in place whatever you choose:

Add an architecture test that fails if Domain references Infrastructure or Application references EF Core. Keep one assembly per layer only if it earns its keep; otherwise use one project with namespaces and the architecture test. Ban framework types in domain and application public signatures in code review. Write repository methods in domain language, not CRUD language. Put I/O at the edges; keep handlers free of HttpContext, DbContext, and connection strings. Expect to bypass the pattern for hot read paths and say so up front.

The core idea survives all the variations: business rules at the center, infrastructure at the edge, dependencies pointing inward, enforced by the compiler or a test. Everything else—project counts, MediatR, CQRS, folder names—is optional scaffolding around that rule. Adopt the rule first, add the scaffolding only when it solves a problem you actually have.

A quick note on .NET versions and tooling

The architecture principles here are version-independent and stable across .NET 6 through .NET 10. What changes with versions is tooling: minimal APIs (introduced in .NET 6) are now a common presentation-layer choice alongside controllers; MediatR's licensing changed in the mid-2020s for certain usage tiers, so teams sometimes substitute a small custom dispatcher or a different mediator package—check the current license for your version before depending on it. Entity Framework Core's performance features (compiled queries, AsNoTracking, source-generated interceptors) evolve with each release, which is exactly why persistence should sit in infrastructure where upgrades don't ripple into the domain. Source-generator-based mapping, Native AOT support for minimal APIs, and improved DI validation are convenient additions but none of them alter the dependency rule. When you evaluate a template, verify its package versions and licensing current as of your target framework rather than trusting an old blog post's specifics.

The bottom line for a .NET team: treat the dependency rule as the architecture, and treat layers, projects, and libraries as replaceable implementation choices. That framing keeps the pattern useful instead of ornamental.