.NET Aspire
Aspire is a code-first orchestration and observability layer for distributed applications, giving teams one application model for services, data stores, queues, containers, executables, and cloud dependencies.
Overview
An AppHost declares resources and relationships in C# or TypeScript. Aspire starts the development topology, injects references and endpoints, evaluates health and dependencies, and exposes logs, metrics, traces, commands, and lifecycle state in the dashboard. It supports multi-language workloads, but it is not an application framework, cloud provider, or production runtime; deployment still needs an explicit target and production-grade infrastructure decisions.
What you will learn
- Explain Aspire's application model and what it does not replace.
- Model projects, containers, executables, data stores, parameters, and dependencies in an AppHost.
- Use resource references and service discovery instead of hardcoded local endpoints.
- Apply health checks, telemetry, logs, traces, and metrics through shared service defaults.
- Run and debug a multi-resource system through the CLI, dashboard, and IDE tooling.
- Test the application model and critical resource journeys in automated pipelines.
- Publish or deploy the model while choosing production identity, networking, storage, scaling, and secrets explicitly.
- Keep AppHost declarations reviewable, portable, secure, and aligned with the real architecture.
Prerequisites
- .NET project and dependency-injection fundamentals.
- Basic distributed application, container, health-check, and OpenTelemetry concepts.
- Docker-compatible container runtime when the model includes container resources.
- A .NET 10 SDK and stable Aspire CLI to run the dedicated service-map sample.
When to use .NET Aspire
Good fit
- Use Aspire when developers must coordinate several services or dependencies consistently from one model.
- Use it to standardize service discovery, health, telemetry, local resource lifecycle, and onboarding.
- Use multi-language resources when one distributed system spans .NET, JavaScript, Python, Java, Go, or other runtimes.
- Use its publish and deployment integrations as inputs to an explicit target-platform design.
Choose another approach when
- Do not present Aspire as a production scheduler, cloud, service mesh, or replacement for Kubernetes or Container Apps.
- Do not hide business logic, migrations, or environment-specific provisioning inside a sprawling AppHost.
- Do not assume a development container has production durability, security, backups, or scale.
- Do not add Aspire to a single-process application unless the application-model and observability benefits justify it.
Key concepts
A C# or TypeScript application model declares services, frontends, databases, caches, queues, containers, executables, and their relationships.
Dependent projects receive resolved endpoints for the resources they reference instead of hardcoded URLs or ports.
Hosting integrations model resources while client integrations configure health, resilience, telemetry, and provider clients inside workloads.
The dashboard shows resource lifecycle, endpoints, commands, structured logs, traces, and metrics across the running application.
References, wait conditions, parent-child relationships, endpoints, parameters, and annotations form an inspectable dependency graph.
A shared project can apply OpenTelemetry, health checks, service discovery, and HttpClient resilience consistently to .NET services.
Aspire testing starts the AppHost under test, resolves resource endpoints, waits for readiness, and exercises real cross-resource journeys.
The application model can produce deployment artifacts or feed target integrations, but production topology and governance remain explicit choices.
Architecture
The AppHost starts and wires together each declared resource, injecting configuration and endpoints while the dashboard observes all of them together.
Conceptual architecture · Adapt to your system context
Implementation walkthrough
Build the critical path deliberately, then verify its observable behavior.
- 01
- 02
- 03
- 04
- 05
- 06
- 07
Code example
The AppHost project describes resources once; dependent projects reference them by name instead of configuring connection strings manually.
var builder = DistributedApplication.CreateBuilder(args);
var postgres = builder.AddPostgres("postgres").AddDatabase("orders");
var cache = builder.AddRedis("cache");
var api = builder.AddProject<Projects.Orders_Api>("orders-api")
.WithReference(postgres)
.WithReference(cache);
builder.AddProject<Projects.Orders_Web>("orders-web")
.WithReference(api);
builder.Build().Run();Testing strategy
Test both the declared resource graph and the behavior of the distributed application it starts.
- Unit-test custom topology rules, naming, parameter validation, and environment-specific choices.
- Use Aspire hosting testing to start the AppHost and wait for named resources to become healthy.
- Resolve endpoints from the model and run real HTTP or messaging journeys instead of hardcoding test ports.
- Exercise missing dependency, slow readiness, restart, transient failure, and cancellation behavior.
- Run container-backed tests in CI with sufficient runtime, port, memory, and diagnostic permissions.
- Preserve AppHost logs, dashboard telemetry, resource events, and test traces when startup or readiness fails.
Security considerations
The AppHost handles powerful configuration and process orchestration, so development convenience must not weaken production identity or secret boundaries.
- Model secrets as parameters or secret references; never commit values or expose them in resource commands and logs.
- Use distinct workload identities and least-privilege access for production resources instead of copying development credentials.
- Bind development endpoints deliberately and do not expose dashboards, databases, or admin ports to untrusted networks.
- Pin and audit Aspire integrations, container images, templates, and CLI versions as supply-chain dependencies.
- Protect dashboard access and telemetry because logs, traces, environment metadata, and endpoints can reveal sensitive architecture.
- Review generated deployment artifacts, role assignments, ingress, egress, TLS, secret stores, and network policies before release.
Performance and scalability
Aspire improves visibility into distributed performance; it does not remove the need for capacity and topology design.
- Use traces to find fan-out, serialization, dependency, and retry latency across resource boundaries.
- Track process and container CPU, memory, restarts, request duration, error rate, queue depth, and datastore saturation.
- Avoid starting unnecessary heavyweight resources in every developer loop; use profiles or external resources where appropriate.
- Use persistent development volumes deliberately and reset state when deterministic tests require isolation.
- Bound dashboard and telemetry retention locally and choose sampled, cost-aware production exporters.
- Load-test the target deployment because local AppHost timing and resource limits do not represent production capacity.
Deployment and operations
Treat Aspire's application model as a deployment input, then make target-platform requirements explicit and reviewable.
- Pin the SDK, CLI, integrations, base images, and workload artifacts used by the model.
- Choose a supported deployment integration or generate artifacts that fit the organization's IaC and promotion workflow.
- Replace development containers with durable managed services where required; define backups, private networking, identity, and availability separately.
- Supply environment parameters and secrets through the deployment system, not AppHost source or committed launch settings.
- Deploy immutable versions, validate resource references and health, observe traces, and use canary or staged traffic where supported.
- Keep production dashboards, alerts, runbooks, scaling, disaster recovery, and cost controls aligned with each declared resource.
Common problems and fixes
A resource never becomes ready
Likely cause: The process exited, a dependency is unhealthy, the health path is wrong, or the container runtime cannot start the resource.
Fix: Inspect resource events, console logs, health details, dependency order, runtime state, ports, and image availability in the dashboard.
A service cannot resolve another service
Likely cause: The AppHost reference is missing, the client used a hardcoded URI, or the resource and client names differ.
Fix: Add the typed reference, use service discovery or the integration client, and compare injected configuration names.
The dashboard has logs but no traces
Likely cause: Service defaults or OpenTelemetry instrumentation is missing, exporters are misconfigured, or no traceable operation ran.
Fix: Verify service-default registration, instrumentation, OTLP endpoint injection, ActivitySource creation, and sampling.
The model works locally but deployment fails
Likely cause: A development-only resource, volume, credential, port, or target integration has no production mapping.
Fix: Review the publish artifact and explicitly map identity, secrets, storage, networking, ingress, scaling, and supported resource types.
AppHost startup is slow or flaky
Likely cause: Too many images restore at once, readiness is inaccurate, stale volumes conflict, or dependency startup exceeds bounds.
Fix: Pin images, pre-pull in CI, improve health checks, use wait conditions, reset only intended state, and capture resource timing.
Package or CLI commands disagree with documentation
Likely cause: The Aspire CLI, AppHost SDK, integrations, or templates are from different release lines.
Fix: Inspect pinned versions, upgrade them as one tested set, regenerate only intended files, and verify the migration notes.
Best practices
- Keep the AppHost declarative; let it describe resources and references instead of embedding business logic.
- Use the dashboard during development to check traces and logs before reaching for a debugger.
- Treat local resource definitions as a starting point, not a production topology; review managed service choices separately.
- Reference resources through typed builders instead of hardcoding hostnames, ports, or connection strings.
- Pin CLI, SDK, integration, and image versions as one tested compatibility set.
- Use stable resource names and small reusable extension methods for repeated platform conventions.
- Keep service defaults focused on cross-cutting infrastructure and out of business logic.
- Test the resource graph and at least one real distributed journey in CI.
Production checklist
- AppHost SDK, CLI, integrations, templates, images, and workload dependencies are pinned and audited.
- Every resource has a stable name, owner, reference graph, health definition, and documented production mapping.
- Service discovery replaces hardcoded endpoints and environment-specific configuration is injected through controlled parameters.
- Secrets are external, identities are least privilege, dashboards are protected, and ingress and egress are reviewed.
- Logs, metrics, traces, resource events, readiness, business outcomes, dashboards, alerts, and diagnostic retention are verified.
- Model and journey tests start the real topology, wait for health, exercise failure, and preserve diagnostics in CI.
- Production IaC defines durable storage, networking, backups, scaling, availability, patching, and disaster recovery.
- Published artifacts are reviewed, immutable, promoted safely, and proven against the actual target environment.
Common interview questions
What problem does .NET Aspire solve that Docker Compose does not fully cover?
It adds .NET-aware service discovery, typed resource references, and built-in OpenTelemetry wiring across projects, so dependent services and dashboards work with less manual configuration than a generic container definition.
Is Aspire a hosting platform?
No. It is an application model and local orchestration/tooling experience; deployment still targets your chosen hosting platform, using Aspire's manifest to describe the resources needed.
How does a project get another resource's connection details?
Through WithReference in the AppHost, which injects configuration and environment variables that the referencing project's client integration reads automatically.
What is the difference between a hosting and client integration?
A hosting integration models and runs a resource in the AppHost. A client integration configures the consuming workload's client, health checks, telemetry, and resilience.
Why are health checks part of the resource graph?
Process start does not mean readiness. Health-aware dependencies let the model and tests wait for a resource that can actually serve work.
Can Aspire coordinate non-.NET workloads?
Yes. The AppHost can be authored in C# or TypeScript and can model projects, executables, containers, and integrations across several languages and runtimes.
Dedicated GitHub sample
Clone, run, test, and modify the focused implementation created for this guide.
Aspire Service Map
A real Aspire 13.4 AppHost coordinating two .NET 10 API resources with typed references, health-aware startup, dashboard observability, topology tests, and Container Apps infrastructure.
- Run
aspire run --project src/AspireServiceMap.AppHost- Test
dotnet test AspireServiceMap.slnx