← Tous les modèles

Minimal APIs, nullable activé, migrations EF Core relues, erreurs ProblemDetails.

Constitution — ASP.NET Core API

Version 1.0.0 · Ratified 2026-11-10

These principles hold for every spec, plan and task of the project. A spec may add rules; it never weakens these.

  1. Minimal APIs. Endpoints are minimal APIs grouped per feature with MapGroup and declared in one extension method per feature. Handlers return TypedResults so the OpenAPI document knows every response.

  2. Nullable enabled. <Nullable>enable</Nullable> and <TreatWarningsAsErrors>true</TreatWarningsAsErrors> are set in Directory.Build.props. The null-forgiving operator ! needs a reason in the review.

  3. EF Core migrations reviewed. Every model change ships its migration and the generated SQL script (dotnet ef migrations script --idempotent) in the same pull request. Migrations run as a deploy step, never through Database.Migrate() at app startup.

  4. ProblemDetails errors. AddProblemDetails and an IExceptionHandler map domain errors to RFC 9457 responses with a stable type. Exception messages and stack traces never reach the client outside development.

  5. Async with cancellation. Every I/O method is async and takes the request’s CancellationToken down to EF Core and HttpClient. .Result and .Wait() fail the review.

  6. Validated input. Request DTOs are records validated (FluentValidation or the built-in validation) before the handler runs; failures return a ValidationProblem. Entities are never bound from or returned to the client.

  7. Options pattern for config. Settings bind to classes with AddOptions<T>().Bind(...).ValidateDataAnnotations().ValidateOnStart(). No IConfiguration["key"] reads inside services.

  8. Integration tests. Each endpoint has tests with WebApplicationFactory against a real database in Testcontainers, covering success, a validation problem and unauthorized access.