Skip to main content

Claude/ChatGPT Prompt to Build a .NET 9 Minimal API with Tests

.NET 9 Minimal API generator: EF Core, FluentValidation, JWT auth, Swagger, Serilog logging, and xUnit integration tests for any resource.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt makes the model a senior .NET engineer and asks for a production-ready .NET 9 Minimal API as working code, not pseudocode. You set [resource], [database], [auth_scheme], and [hosting], and it returns a wired Program.cs, route-grouped CRUD endpoints with paging, FluentValidation validators returning RFC 7807 problem details, JWT auth with role policies, EF Core entities plus a migration command, and xUnit integration tests using WebApplicationFactory.

The structure works because it bakes in the disciplines teams usually bolt on too late — validation, auth, and integration tests on day one. [resource] names the entity every endpoint and entity revolves around, [database] selects the EF Core provider so the DbContext and connection setup match, [auth_scheme] shapes the JWT and policy configuration on mutating endpoints, and [hosting] (for example, containerized on ECS) informs how the app is configured to run. Returning each concern as a separate labelled code block keeps the output readable and lets you drop files into a project one at a time, rather than untangling one giant listing that mixes startup, endpoints, and tests together.

When to use it

  • You're starting a .NET 9 Minimal API and want a clean, opinionated skeleton.
  • You want FluentValidation and RFC 7807 problem details wired from the start.
  • You need JWT auth with role or policy checks on mutating endpoints.
  • You want EF Core entities, configuration, and an initial migration generated together.
  • You want integration tests covering happy path, validation failure, and 401 on day one.
  • You're bringing the same validation-and-tests discipline you use in other stacks to .NET.

Example output

Expect separate, labelled code blocks: Program.cs with DI, EF Core, Serilog, and Swagger; the endpoint definitions grouped with route groups; the FluentValidation validators; the DbContext and entity configuration; and the xUnit test class. It closes with the dotnet CLI commands to run the API and execute the tests, including the migration command.

Pro tips

  • Set [database] to your real engine (SQL Server, PostgreSQL, SQLite) so the EF Core provider and migration are correct.
  • Wire the WebApplicationFactory tests from step 6 first; they catch DI and auth mistakes before staging does.
  • Make [auth_scheme] specific about roles and policies so the mutating-endpoint guards match your access model.
  • Use [hosting] to signal config needs — containerized hosting changes how you handle connection strings and secrets.
  • Run the generated migration command in a throwaway database first to confirm the schema is what you expect.
  • Ask it to add a second resource afterward to confirm the route-group and validation pattern scales cleanly.
  • Keep the paging on the GET list endpoint; an unpaged list is the first thing to fall over once [resource] accumulates real rows.
  • Review the JWT setup against your identity provider's actual token claims rather than trusting the default policy names verbatim.

Frequently Asked Questions

Which databases does the EF Core setup support?
Whatever you put in `[database]`. The default is SQL Server, but setting it to PostgreSQL, SQLite, or another EF Core-supported engine changes the provider, the DbContext configuration, and the generated migration command accordingly.
Does it generate real integration tests or just unit test stubs?
It generates xUnit integration tests using WebApplicationFactory, covering the happy path, a validation failure, and a 401 unauthorized case. These exercise the real DI and auth pipeline, which is where most Minimal API misconfigurations surface.
What does RFC 7807 problem details mean in the output?
It means validation failures and errors are returned as standardized problem-detail JSON responses rather than ad-hoc error shapes. The FluentValidation validators are wired to produce these, giving clients a consistent, machine-readable error format.
Is the output really deployable code?
Yes, the prompt asks for working code, not pseudocode, returned as separate blocks for each file plus the CLI commands to run and test. You should still review the auth configuration and run the tests before deploying to a real environment.
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.

More 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