# ASP.NET Core (.NET 9/10) instructions

## Commands
`dotnet build -warnaserror` · `dotnet test` · `dotnet format --verify-no-changes`

## Conventions
- Nullable reference types are on; fix warnings, don't suppress them with `!`.
- Minimal APIs grouped per feature with `MapGroup("/orders")` in an extension method (`app.MapOrders()`). Return `TypedResults` (`Results<Ok<OrderDto>, NotFound>`) so OpenAPI is accurate.
- DTOs are `record`s. Never return EF entities.
- Validate input (FluentValidation or DataAnnotations, whichever the repo uses) and return `TypedResults.ValidationProblem`.
- Errors produce `ProblemDetails` via `AddProblemDetails()` and an exception handler; no try/catch in every endpoint.
- Async all the way: `async Task`, pass `CancellationToken` from the endpoint down to EF calls. No `.Result` or `.Wait()`.
- EF Core: `AsNoTracking()` for reads, projections with `Select` to DTOs, migrations with `dotnet ef migrations add <Name>`.
- Options pattern (`IOptions<T>` with validation) for config. Secrets via user-secrets locally, never `appsettings.json`.
- Logging via `ILogger<T>` with message templates (`"Order {OrderId} shipped"`), not string interpolation.

## Tests
xUnit + `WebApplicationFactory<Program>` for endpoint tests; Testcontainers for the database.

## Don't
Don't add MediatR or a repository layer over EF unless the project already has one.
