Passing Route Data to Laravel Blade Templates
When a Laravel web route needs to display information from its URL, the route or its controller must pass that information to…
When a.NET Web API grows past basic data entry and retrieval, developers often end up mixing business rules into HTTP endpoints, database queries, and external service calls. Clean Architecture keeps these responsibilities apart. Your API layer handles HTTP, your application layer runs use cases (the operations the API supports), your domain layer holds the business rules, and your infrastructure layer talks to databases and external services.
I apply this by keeping business decisions independent of ASP.NET Core and Entity Framework Core (EF Core), the.NET framework for working with databases. Outer layers can call the core, while the core never depends on technologies at the edges. Because of that, you can test business behavior on its own, and you can swap out an infrastructure implementation without changing the domain. You don't need four projects, a mediator library, or microservices to use Clean Architecture. Match the structure to the complexity of your API.
Clean Architecture is about which projects and classes reference each other. In a typical.NET setup, the domain holds business concepts and rules, while the application layer defines use cases and the interfaces they need. Infrastructure implements those interfaces, and the API translates HTTP requests and responses. Microsoft's guidance describes the Application Core as independent of the UI and infrastructure, with those outer parts depending on the core.
You might name your projects Domain, Application, Infrastructure, and WebApi, though those names are conventions. What matters is that Domain never references EF Core or ASP.NET Core, and Application stays unaware of which database provider or HTTP client does the external work. Project references let the compiler enforce these boundaries for you. If the Domain project does not reference Infrastructure, domain code cannot use infrastructure types.
For a small API, you can put everything in one project organized by feature and keep the same boundaries with less setup. Microsoft's architecture guidance points out that a simple CRUD service may not benefit from complex domain patterns. I add a separate project or abstraction only when it protects a boundary that matters, rather than to match a diagram.
Your API layer deals with HTTP. An endpoint or controller reads input, validates the request, calls an application use case, and turns the result into an HTTP response. Keep database queries and business decisions out of it so another entry point won't have to duplicate them.
The application layer runs operations a user can request, like placing an order or fetching an account summary. A use case takes a defined input and coordinates the steps to finish the job. It can depend on an interface like IOrderRepository or IEmailSender, which states what the dependency does without choosing how it works. Infrastructure supplies the concrete class.
The domain layer enforces business rules that must hold true regardless of how a request arrives. In a simple catalog API, data-focused entities may be all you need. As business rules get more involved, entities with behavior, value objects, and aggregates become useful. An aggregate groups related domain objects, and the application updates that group through a single root object to keep the data consistent. Microsoft recommends matching domain-model complexity to business complexity instead of building a heavy model for every service.
Infrastructure handles technical details such as EF Core queries, database connections, file storage, and external API calls. The Web API host connects those concrete implementations to the core's interfaces through dependency injection, a.NET feature that supplies an object's dependencies at runtime. Microsoft documents grouping related registrations in extension methods, so your Infrastructure project can expose an AddInfrastructure method for the API to call at startup.
Request validation and domain invariants solve different problems. Request validation checks whether an incoming HTTP payload has the right shape and gives the caller clear feedback. A domain invariant protects business state even when a caller bypasses the API endpoint.
An endpoint can reject a missing or malformed order address before it ever calls the use case. At the same time, the domain code that creates an order should block the order from entering an invalid state. Microsoft's guidance puts invariant enforcement in domain entities, especially aggregate roots. That way, a background job or a second API path cannot quietly skip the rule.
Your API should also turn expected failures into consistent HTTP responses. ASP.NET Core supports Problem Details, a standard JSON format for HTTP errors. In ASP.NET Core 10, MVC produces Problem Details for controller error results with status codes of 400 or higher by default. If middleware produces a response, you need to configure AddProblemDetails. Content negotiation, where the server reads request headers to pick a response format, can also affect whether the server writes a response body.
Minimal API binding failures need extra attention in ASP.NET Core 10. In Development, ThrowOnBadRequest defaults to true, so a binding failure throws an exception and runs through your exception handling. Outside Development, it defaults to false, so the framework writes a 400 response directly and skips custom exception handlers. If your exception handler does not preserve the status code in both the HTTP response and the Problem Details payload, an unhandled BadHttpRequestException can turn into a 500 error. Check the behavior and configuration for your target ASP.NET Core version, and test both your endpoint style and the Accept headers your clients send.
The API host acts as the composition root where you connect interfaces to concrete classes. Infrastructure registers the database repository, and the host registers Infrastructure's services. Because the use case still depends only on the repository interface, you can change the database provider without touching the business rule.
Pay close attention to service lifetimes when you wire up dependencies. ASP.NET Core generally creates a scoped service once per web request. Never inject a scoped service, such as a database context, into a singleton service. In Development, scope validation catches this mistake for you. If you resolve a scoped service from the root provider, it effectively lives as a singleton. Check how long each registration lives and how the container disposes of it, rather than picking a lifetime only to make the container accept the dependency.
You can test domain rules and use cases without starting a web server. These tests verify your core contracts and show whether a business decision works without HTTP routing or database wiring. When it is practical, test your persistence code against the same database system you use in production, because database providers behave differently.
When you need a test double, EF Core's testing guidance recommends a repository abstraction above EF Core, while noting that this layer adds implementation and maintenance work. You can use SQLite in-memory if adding a repository boundary is not practical, though SQLite does not match every production provider's behavior. EF Core's InMemory provider does not behave like a relational database and cannot replace one.
To cover the full HTTP pipeline, write integration tests for the API. ASP.NET Core's WebApplicationFactory<TEntryPoint> spins up a test host so your test client can send requests through routing, model binding, middleware, dependency injection, and serialization. Check the documentation for your target ASP.NET Core version, such as Microsoft's ASP.NET Core 10 integration-testing reference. These tests catch wiring mistakes and HTTP contract failures that isolated unit tests miss.
Clean Architecture does not require CQRS (separating commands that change state from queries that read data) or a mediator library that dispatches requests to handlers. Those patterns can make complex use cases clearer, but each one adds extra concepts and code to maintain. Wrapping every class in an interface or putting a repository around every EF Core query also adds indirection without necessarily protecting a useful boundary.
Templates show options you can borrow, and you don't have to treat them as strict rules. The Ardalis Clean Architecture template, for example, includes both a multi-project layout and a smaller vertical-slice option that groups code by feature. Pick the layout whose boundaries help your team keep business rules separate from infrastructure changes. Clean Architecture works as well in a monolith as it does in a distributed service, and it does not require independently deployed microservices.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com