Org Skills

Hosting models: container, serverless, and what Aspire does

Supporting material for dotnet-architecture. Agents load it on demand; it ships inside the skill folder.

RawSource

Verified 2026-09 against https://aspire.dev/whats-new/aspire-13/, https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide and https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container.

1. Container or serverless

Force Long-running container Serverless function
Traffic shape Steady, or spiky with a warm pool Bursty, idle most of the day, or event-triggered
Cold start Irrelevant after deploy The design constraint: trim dependencies, avoid heavy DI graphs, consider ReadyToRun
Connection pooling One pool per instance, predictable Each instance opens its own pool; a scale-out spike can exhaust the database — put a pooler in front
In-process state Caches, channels, background services all work Nothing survives an invocation; every background job needs an external trigger
Long work Fine Hard limits on execution time; long work must become a durable workflow
Cost at low volume Pays while idle Pays per execution

Default to a container for an HTTP API with any steady traffic, and reach for functions when the unit of work is genuinely an event. Mixing both in one system is normal: the API is a container, the "resize this upload" handler is a function.

On Azure Functions, use the isolated worker model — it runs your own Program.cs on a current .NET, so the DI, options, logging and resilience patterns from dotnet-development apply unchanged. The legacy in-process model is tied to the host's runtime version and should not be started new.

2. Container image

dotnet publish can produce an image without a Dockerfile:

dotnet publish -c Release \
  /t:PublishContainer \
  -p:ContainerBaseImage=mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled \
  -p:ContainerRepository=acme/orders-api

Chiseled images contain no shell and no package manager, which removes most of the image's CVE surface and most of the ways to debug it from inside — that trade is the point. They run as a non-root user by default. When you need a shell for triage, the -noble-chiseled-extra variants exist, but a debug sidecar is the better habit.

A multi-stage Dockerfile is still the right choice when the build needs steps dotnet publish does not own (front-end bundling, native dependencies, custom certificates).

Image, probes, signals and graceful shutdown are covered once in service-operability; do not re-specify them per service.

3. Aspire 13

Aspire is a local orchestration and composition tool. An app host project describes the graph — your services, a Postgres container, a message broker, a Redis instance — and starts the whole thing with one command, wiring connection strings and OpenTelemetry into every resource and showing traces in its dashboard.

<!-- AppHost.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
  <Sdk Name="Aspire.AppHost.Sdk" Version="13.0.0" />
  ...
</Project>
aspire run       # start the graph locally
aspire publish   # emit deployment artefacts for a target

What it is genuinely good at:

  • Replacing a hand-maintained docker-compose.yml plus a page of "how to run this locally".
  • Service defaults: one shared project that adds OpenTelemetry, health endpoints, service discovery and resilience to every service the same way.
  • Integration tests that start real dependencies through the app host (Aspire.Hosting.Testing), covered in dotnet-testing.

What to decide separately:

  • Deployment. aspire publish and aspire deploy generate artefacts for a target platform. Judge them against the platform your organisation already runs — if you have working pipelines and infrastructure as code, keep them and use Aspire for local development only.
  • Coupling. The app host is a development dependency; nothing in your service code should require it to exist. If a service only starts under Aspire, the wiring has leaked.

Aspire 13 dropped ".NET" from the name and treats Python and JavaScript as first-class resources, so the jump in version numbers (9 → 13) is a rename plus a scope change, not thirteen major .NET versions. Search for "Aspire 13", not ".NET Aspire", or you will find documentation for a different product generation.