Skip to main content

ASP.NET Core Minimal API with Clean Architecture

Build an ASP.NET Core minimal API following Clean Architecture — endpoint grouping, FluentValidation, global error handling, DI, and OpenAPI documentation.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt scaffolds an ASP.NET Core 8 minimal API for a given [api_purpose] following Clean Architecture. It sets up [project_count] projects — API, Application, Domain, Infrastructure — with the dependency flow pointing inward, then builds [endpoint_groups] endpoint groups using MapGroup(), integrates FluentValidation returning ProblemDetails for [validation_scenarios], and adds global exception handling, DI via [di_pattern], OpenAPI with [auth_method], and health checks for [health_dependencies].

The structure works because Clean Architecture only pays off if the dependency flow actually points inward, so the prompt makes that the first thing it establishes. Mapping domain exceptions to ProblemDetails and grouping endpoints with MapGroup() is the combination that keeps the API consistent as it grows. The [di_pattern] choice and correct middleware ordering — exception handling, authentication, authorization, CORS, rate limiting — are spelled out so the pipeline behaves predictably from the start.

When to use it

  • You are starting a new minimal API and want Clean Architecture structure from the first commit
  • You need endpoint groups organized with MapGroup() and OpenAPI tag metadata for [endpoint_groups]
  • You want FluentValidation wired to return consistent ProblemDetails for [validation_scenarios]
  • You need a global exception handler mapping domain exceptions to correct HTTP status codes
  • You want DI registered cleanly via [di_pattern] with correct service lifetimes
  • You need health-check endpoints for dependencies like [health_dependencies]

Example output

Expect a project scaffold and code: a four-project solution with the dependency arrows pointing inward, endpoint-group registrations using MapGroup(), a ValidationFilter returning ProblemDetails, exception-handling middleware, DI registration code with scoped, singleton, and transient lifetimes assigned correctly, Swagger or Scalar configuration including the security scheme, health-check endpoints, and a correctly ordered middleware pipeline.

Pro tips

  • State [api_purpose] concretely — an inventory system drives different endpoint groups and domain models than a generic CRUD API
  • Keep the dependency flow strict: Domain depends on nothing, and the prompt will respect that only if you don't let infrastructure leak inward
  • Be specific in [validation_scenarios] so the generated FluentValidation rules cover real business constraints, not just non-null checks
  • Pick a [di_pattern] your team understands; Scrutor assembly scanning reduces boilerplate but hides registrations, so weigh that against explicit registration
  • Watch service lifetimes — the classic bug is injecting a scoped DbContext into a singleton, and the prompt assigns lifetimes but you should verify them
  • Confirm middleware order matches the prompt's sequence; exception handling must sit outermost or thrown errors bypass your ProblemDetails formatting
  • Add OpenAPI tag metadata and example requests per group so the generated Swagger or Scalar docs are genuinely usable by the clients consuming [api_purpose]
  • Wire each item in [health_dependencies] to a real readiness probe rather than a hardcoded healthy response, or the endpoint will report green while a dependency is down
  • Keep validation in FluentValidation rather than scattering checks into endpoints, so [validation_scenarios] rules stay in one place as the API grows

Frequently Asked Questions

Does this enforce Clean Architecture dependency rules?
It structures the solution so dependencies point inward, with Domain depending on nothing and outer layers depending on inner ones. The prompt sets this up, but enforcement is ongoing — you should add architecture tests or reviews to catch infrastructure concerns leaking into the Domain or Application layers as the project grows.
Why use MapGroup() instead of individual endpoint mappings?
`MapGroup()` lets you apply a shared route prefix, filters, and OpenAPI tags to a set of related endpoints in `[endpoint_groups]`. This keeps the API consistent and reduces repetition as it grows, rather than configuring authentication, validation, and metadata separately on every individual endpoint.
How does validation error formatting work here?
The prompt integrates FluentValidation through a ValidationFilter that returns responses in ProblemDetails format for invalid requests. Combined with the global exception handler mapping domain exceptions to the same format, clients receive consistent, machine-readable error responses across both validation failures and runtime errors.
Is this for .NET 8 specifically or any version?
The prompt targets ASP.NET Core 8 minimal APIs and references .NET 8 features. Much of the structure applies to later versions too, but minimal API APIs and middleware helpers evolve between releases, so confirm method signatures and recommended patterns against the .NET version you actually deploy on.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in C# & .NET Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support