A dotnet new webapi is created quickly, but it is not yet a service I would put into a container. It lacks validation, uniform error responses, health endpoints and a Dockerfile that does not run as root. This boilerplate adds exactly that to a single project, Notes.Api, and sticks to what I built and checked with curl myself on 14 November 2026. The most important finding came out of that: with AddValidation(), a record without public builds without errors but is never validated. The API then answers 201 Created instead of 400 Bad Request. If you are upgrading an existing project rather than starting fresh, the path is in my post on migrating from .NET 8 to .NET 10.
What dotnet new webapi provides and what is missing
The template as of SDK 10.0.401
My test ran in a throwaway container from mcr.microsoft.com/dotnet/sdk:10.0 with SDK 10.0.401 and runtime 10.0.12 on linux/arm64, with 2 CPUs and 2 GB of RAM. On the same day Microsoft already listed SDK 10.0.404 and runtime 10.0.15, so the test sat three patch levels below current. Without further flags the template creates a Minimal API, not controllers. The project file contains the Web SDK, the target framework net10.0, Nullable, ImplicitUsings and a package reference to Microsoft.AspNetCore.OpenApi in the version of the SDK level, 10.0.12 in my case.
The target framework has had a fork since 10 November 2026: .NET 11 shipped that day as an STS release, and SDK 11.0.100 creates net11.0 by default. If you want to stay on net10.0, you pass dotnet new webapi -n Notes.Api -f net10.0, which as a rule requires an installed 10.x SDK. Support for .NET 8 and .NET 9 ended on the same day.
The ingredients the template does not have
The generated Program.cs calls AddOpenApi(), MapOpenApi() inside the Development block and UseHttpsRedirection(), and serves the weather endpoint. There is no route group, no TypedResults, no service from dependency injection, no validation, no ProblemDetails and no health endpoint. Exactly these six things are added now, and one is removed: the HTTPS redirect, because TLS terminates at the reverse proxy in my setup.
Notes.Api: one Program.cs for the container
+----------------+ +--------------------------------------------+
| Reverse Proxy | ---> | Kestrel :8080 |
| TLS ends here | | UseExceptionHandler, UseStatusCodePages |
+----------------+ | /healthz/live /healthz/ready |
| /api/notes (MapGroup + AddValidation) |
| /openapi/v1.json (Development only) |
+--------------------------------------------+
Route group, TypedResults and the store from DI
The complete Program.cs, exactly as it built for me:
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http.HttpResults;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
builder.Services.AddProblemDetails();
builder.Services.AddValidation();
builder.Services.AddSingleton<INoteStore, InMemoryNoteStore>();
builder.Services.AddHealthChecks(); // optional: .AddCheck(..., tags: ["ready"])
var app = builder.Build();
app.UseExceptionHandler(); // writes ProblemDetails because AddProblemDetails is registered
app.UseStatusCodePages(); // 4xx/5xx without body -> ProblemDetails
if (app.Environment.IsDevelopment())
{
app.MapOpenApi(); // /openapi/v1.json
}
// no UseHttpsRedirection: TLS terminates at the reverse proxy
app.MapHealthChecks("/healthz/live", new HealthCheckOptions { Predicate = _ => false });
app.MapHealthChecks("/healthz/ready", new HealthCheckOptions { Predicate = c => c.Tags.Contains("ready") });
var notes = app.MapGroup("/api/notes");
notes.MapGet("/", (INoteStore store) => TypedResults.Ok(store.All()));
notes.MapGet("/{id:int}", Results<Ok<Note>, NotFound> (int id, INoteStore store) =>
store.Find(id) is { } note ? TypedResults.Ok(note) : TypedResults.NotFound());
notes.MapPost("/", (CreateNote input, INoteStore store) =>
{
var note = store.Add(input.Title);
return TypedResults.Created($"/api/notes/{note.Id}", note);
});
app.Run();
record Note(int Id, string Title);
// in .NET 10 the type MUST be public, otherwise AddValidation skips it (see the test below)
public record CreateNote([property: Required, MinLength(3), MaxLength(80)] string Title);
interface INoteStore
{
IReadOnlyList<Note> All();
Note? Find(int id);
Note Add(string title);
}
// demo store without a lock, fine for the test, not for concurrent writes
sealed class InMemoryNoteStore : INoteStore
{
private readonly List<Note> _notes = [];
public IReadOnlyList<Note> All() => _notes;
public Note? Find(int id) => _notes.FirstOrDefault(n => n.Id == id);
public Note Add(string title)
{
var note = new Note(_notes.Count + 1, title);
_notes.Add(note);
return note;
}
}
MapGroup("/api/notes") bundles the three endpoints under one prefix; filters or metadata on the group behave as if added to each endpoint individually. The INoteStore store parameter comes from the container without [FromServices] because the type is registered as a service. CreateNote input is bound implicitly from the JSON body on POST. For the GET with two outcomes the return type Results<Ok<Note>, NotFound> has to be explicit, because the compiler cannot infer a common type from two different TypedResults types. In exchange, both response codes land in the OpenAPI document without Produces(), and an accidental TypedResults.BadRequest() in this handler is a compiler error, not a production finding.
ProblemDetails, health endpoints and no HTTPS redirect
AddProblemDetails() plus UseExceptionHandler() and UseStatusCodePages() make sure an error response without a body of its own comes out as application/problem+json, including a 404 on an unknown path. One condition from the docs: the client's Accept header must include a content type supported by the registered ProblemDetails writer (default application/json). Without these three lines Kestrel returns a 500 without a body on an unhandled exception in Production, provided the response headers have not been sent yet (after that the server closes the connection), and a 404 arrives with an empty body. Important: UseExceptionHandler() without arguments throws an InvalidOperationException at startup if no fallback is configured; in this boilerplate AddProblemDetails() plays that role.
The health endpoints follow the convention from the docs: /healthz/live filters out all checks and only says "the process answers", /healthz/ready runs the checks tagged ready. Without a registered check both return 200 and the plain text Healthy; Unhealthy becomes 503. The middleware sets Cache-Control: no-store, no-cache against caching. How a container orchestrator uses these endpoints is covered in my post on HEALTHCHECK and restart_policy.
The test that returned 201 instead of 400
Variants with and without public, two results
After dotnet build -c Release (Build succeeded, 0 warnings, 14.47 seconds according to "Time Elapsed", a single measurement) and dotnet publish -c Release -o /tmp/out (du -sh reports 928K, that is binary kilobytes, framework-dependent) the app started as Production on port 8080. Then I sent POST /api/notes with {"title":"ab"} against the rule MinLength(3). My first version had declared the record the way the template does, without an access modifier. The response:
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Location: /api/notes/1
{"id":1,"title":"ab"}
With public record CreateNote(...), otherwise identical:
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
{"type":"https://tools.ietf.org/html/rfc9110#section-15.5.1","title":"One or more validation errors occurred.","status":400,"errors":{"Title":["The field Title must be a string or array type with a minimum length of '3'."]},"traceId":"00-..."}
I built further variants: attributes on the parameter instead of [property: ...], <InterceptorsNamespaces> set in the project file or not, each with and without public, though not every conceivable combination of these three traits. All variants I built compiled with "Build succeeded." and no warning. Result: in each of them only public made the difference, attribute placement and InterceptorsNamespaces did not matter.
Declaration of CreateNote |
Response to {"title":"ab"} |
|---|---|
record CreateNote(...) without modifier, i.e. internal |
201 Created |
public record CreateNote(...) |
400 Bad Request |
The cause is in the source generator
AddValidation() relies on a source generator that produces metadata for the validatable types at build time. In the release/10.0 branch, ValidationsGenerator.TypesParser.cs says in lines 77 and 78:
// Skip types that are not accessible from generated code
if (typeSymbol.DeclaredAccessibility is not Accessibility.Public)
The same check appears three more times for properties and their getters. A record without a modifier is internal in C#, so in .NET 10 it drops out, the attributes in the code have no effect, and there is no exception and no log entry. The Learn page on validation lists this under "Troubleshoot generated validation metadata" as a point to confirm: "Validated types and properties are accessible to generated code." With SDK 10.0.401 I got no build warning for it; as of 14 November 2026 the docs list the analyzers ASP0033 to ASP0038 only from .NET 11 on. If you write Program.cs with top-level statements you leave the modifier out almost automatically; the template itself declares record WeatherForecast(...) exactly like that. That is why a negative test with an invalid body belongs in every test suite that relies on AddValidation.
Dockerfile: non-root on port 8080
Standard image versus chiseled
The Dockerfile follows the official aspnetapp sample from the dotnet-docker repository at its .NET 10 state; I did not build it on the production server, only changed the project name and removed the comment lines:
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG TARGETARCH
WORKDIR /source
COPY --link Notes.Api/*.csproj .
RUN dotnet restore -a $TARGETARCH
COPY --link Notes.Api/. .
RUN dotnet publish -a $TARGETARCH --no-restore -o /app
FROM mcr.microsoft.com/dotnet/aspnet:10.0
EXPOSE 8080
WORKDIR /app
COPY --link --from=build /app .
USER $APP_UID
ENTRYPOINT ["./Notes.Api"]
Put the official sample's .dockerignore next to it (**/bin/, **/obj/), otherwise COPY --link Notes.Api/. . copies local build artefacts into the build stage and overwrites the result of dotnet restore.
The images set ASPNETCORE_HTTP_PORTS=8080 and APP_UID=1654. Port 8080 instead of 80 has been the default since .NET 8, because a non-root user may not bind a privileged port in some environments. The standard image still runs as root as long as USER $APP_UID is missing. For chiseled the opposite holds: non-root is the default there, but shell, package manager, ICU and tzdata are missing, so the app runs in globalization-invariant mode; if you need cultures or time zones, take 10.0-noble-chiseled-extra. The basics of build and runtime stages are in my post on the multi-stage Dockerfile for Node and .NET.
What the images weigh on arm64
Measured with docker inspect on the locally present images, linux/arm64, uncompressed, all carrying ASP.NET Core 10.0.12:
| Image | Size | USER in image | ICU and tzdata | Shell |
|---|---|---|---|---|
aspnet:10.0 (Ubuntu 24.04) |
262 MB | root, USER $APP_UID required |
yes | yes |
aspnet:10.0-noble-chiseled |
131 MB | 1654 | no, invariant mode | no |
aspnet:10.0-alpine |
130 MB | root | no, invariant mode | yes |
sdk:10.0 (build stage only) |
974 MB | root | yes | yes |
So the standard image is twice the size of chiseled. I still stay with the standard image here: it ships ICU and tzdata, and it has a shell that lets me look around inside the running container. I would have an app like this checked from the outside: the reverse proxy or monitoring then queries /healthz/live. If you check from the outside as I do and need neither a shell nor ICU, you can switch straight to 10.0-noble-chiseled and save half.
Where I deviate from the template default
No UseHttpsRedirection behind the proxy
Behind a reverse proxy that terminates TLS, UseHttpsRedirection and UseHsts put the site into an infinite loop according to Microsoft, because Kestrel does not know the scheme of the original request; the exception is IIS, whose integration configures the forwarded headers itself. Without an HTTPS endpoint the middleware also logs the warning "Failed to determine the https port for redirect." Instead of the redirect I would set ASPNETCORE_FORWARDEDHEADERS_ENABLED=true in the deployment, but only if the proxy on the same Docker network is the only sender; I did not test that. Microsoft warns that this flag does not restrict KnownProxies.
.NET 10 instead of .NET 11
The obvious reasoning "LTS runs longer" does not hold this time: .NET 10 and .NET 11 both end on 14 November 2028. I stay on .NET 10 because the line has several patch releases of maturity with 10.0.15, the 10.0 image tags are labelled Long-Term Support, and three details of this boilerplate change with .NET 11: the OpenAPI document defaults to version 3.2 instead of 3.1 there, validation gains the analyzers and asynchronous attributes, and the public requirement for the type goes away: according to the generator source in release/11.0, an internal record is enough there, but its properties still have to be public. I derived that from source code and docs rather than testing it. For a boilerplate that others are meant to take over, that counts for more than features a few days old. In a client project in .NET development I make this decision per project.
Questions on the first build
Why does /openapi/v1.json answer with 404 in the container?
Because MapOpenApi() sits inside the IsDevelopment() block in the template, and a container with neither DOTNET_ENVIRONMENT nor ASPNETCORE_ENVIRONMENT set runs as Production. If only one of the two variables is set and it says Development, the container serves the document too. The method code itself contains no environment check; the protection is the block in Program.cs.
Where is the Swagger UI?
No longer in the template. Since .NET 9, ASP.NET Core generates the OpenAPI document itself through Microsoft.AspNetCore.OpenApi, and the template project file in release/10.0 references only this package, which ships no UI. You add a UI such as Scalar or Swagger UI as a separate package, according to the docs in Development only.
How do I check /healthz in the container when curl is missing?
According to the health check docs, curl is missing from the .NET Linux images; that holds for the aspnet runtime images, whereas the SDK image installs curl in its Dockerfile. In the standard image you can install it, in Alpine the bundled wget replaces the call, in chiseled neither works; for that case the chiseled docs describe the Chisel slices route.
Official docs for further reading
Next step: CI and EF Core
Next I put this boilerplate into CI, as in my post on GitHub Actions for .NET with push to GHCR, and replace the demo store with EF Core.
Sources I checked
The most important of the sources I checked:
- Validation in ASP.NET Core, including troubleshooting missing metadata
- Health checks in ASP.NET Core
- Handle errors in ASP.NET Core
- Ubuntu Chiseled .NET images and the aspnetapp Dockerfile at its .NET 10 state
- ValidationsGenerator.TypesParser.cs, branch release/10.0
Note: The articles on this blog are produced with the help of AI and are editorially reviewed before publication. Editorial responsibility lies with Emre Yurtbay (see the legal notice).