Implement GitOps workflows with ArgoCD and Flux for automated, declarative Kubernetes...
npx skills add managedcode/dotnet-skills --skill "dotnet-aspire"
Install specific skill from multi-skill repository
# Description
Use .NET Aspire to orchestrate distributed .NET applications locally with service discovery, telemetry, dashboards, and cloud-ready composition for cloud-native development.
# SKILL.md
name: dotnet-aspire
version: "1.0.0"
category: "Cloud"
description: "Use .NET Aspire to orchestrate distributed .NET applications locally with service discovery, telemetry, dashboards, and cloud-ready composition for cloud-native development."
compatibility: "Requires .NET 8+ and Aspire workload installed."
.NET Aspire
Trigger On
- orchestrating multiple .NET services locally
- setting up service discovery between microservices
- configuring telemetry, health checks, and dashboards
- building cloud-native .NET applications
- managing dependencies like Redis, PostgreSQL, RabbitMQ in development
Documentation
References
- patterns.md - Detailed AppHost patterns, service discovery, integrations, health checks, resilience, and testing patterns
- deployment.md - Azure Container Apps deployment, manifest generation, CI/CD integration, and production configuration
Core Concepts
Three Pillars of Aspire
- Orchestration β Define your app's architecture in code
- Integrations β Pre-configured connections to services (Redis, SQL, etc.)
- Service Discovery β Automatic resolution of service URLs
Project Structure
MyApp/
βββ MyApp.AppHost/ # Orchestration project
β βββ Program.cs # Defines all services and dependencies
βββ MyApp.ServiceDefaults/ # Shared service configuration
β βββ Extensions.cs # OpenTelemetry, health checks, resilience
βββ MyApp.Api/ # Your API project
βββ MyApp.Web/ # Your web frontend
Workflow
- Start with the AppHost:
- Add all services, databases, and dependencies
- Define relationships and references
-
Configure environment-specific settings
-
Use ServiceDefaults for cross-cutting concerns:
- OpenTelemetry (logging, tracing, metrics)
- Health checks
-
Resilience policies (Polly)
-
Use built-in integrations:
- Redis, PostgreSQL, SQL Server, RabbitMQ, Azure services
-
Each integration auto-configures connection strings
-
Run with the dashboard:
dotnet run --project MyApp.AppHost- View logs, traces, and metrics in one place
AppHost Patterns
Basic Service Orchestration
var builder = DistributedApplication.CreateBuilder(args);
// Add infrastructure
var redis = builder.AddRedis("cache");
var postgres = builder.AddPostgres("db")
.AddDatabase("orders");
// Add services with dependencies
var api = builder.AddProject<Projects.MyApp_Api>("api")
.WithReference(postgres)
.WithReference(redis);
var web = builder.AddProject<Projects.MyApp_Web>("web")
.WithReference(api); // Service discovery automatic
builder.Build().Run();
Service Discovery Usage
// In your API client configuration
builder.Services.AddHttpClient<OrdersClient>(client =>
{
// "api" is resolved automatically via service discovery
client.BaseAddress = new Uri("https+http://api");
});
Named Endpoints
// AppHost
var api = builder.AddProject<Projects.Api>("api")
.WithHttpEndpoint(port: 5001, name: "public")
.WithHttpEndpoint(port: 5002, name: "internal");
// Client usage
client.BaseAddress = new Uri("https+http://_internal.api");
ServiceDefaults Pattern
public static class Extensions
{
public static IHostApplicationBuilder AddServiceDefaults(
this IHostApplicationBuilder builder)
{
// OpenTelemetry
builder.ConfigureOpenTelemetry();
// Health checks
builder.AddDefaultHealthChecks();
// Resilience
builder.Services.ConfigureHttpClientDefaults(http =>
{
http.AddStandardResilienceHandler();
});
// Service discovery
builder.Services.AddServiceDiscovery();
return builder;
}
}
Built-in Integrations
| Integration | Package | Usage |
|---|---|---|
| Redis | Aspire.StackExchange.Redis |
Caching, pub/sub |
| PostgreSQL | Aspire.Npgsql |
Relational data |
| SQL Server | Aspire.Microsoft.Data.SqlClient |
Relational data |
| RabbitMQ | Aspire.RabbitMQ.Client |
Messaging |
| Azure Storage | Aspire.Azure.Storage.Blobs |
Blob storage |
| MongoDB | Aspire.MongoDB.Driver |
Document data |
Anti-Patterns to Avoid
| Anti-Pattern | Why It's Bad | Better Approach |
|---|---|---|
| Hardcoded URLs | Breaks service discovery | Use WithReference() |
| Manual connection strings | Error-prone, not portable | Use integrations |
| Skipping ServiceDefaults | No telemetry or resilience | Always include |
| One giant AppHost | Hard to maintain | Split by domain |
Dashboard Features
- Structured Logs β All services in one view
- Distributed Tracing β Request flow across services
- Metrics β CPU, memory, custom metrics
- Resources β Service health and endpoints
Deployment
Azure Container Apps
azd init
azd up
Docker Compose Export
dotnet run --project MyApp.AppHost -- --publisher manifest
Best Practices
- Always use ServiceDefaults β Get telemetry for free
- Use integrations over manual config β Connection strings are managed
- Reference services explicitly β
WithReference()enables discovery - Keep AppHost simple β Orchestration only, no business logic
- Use environment-specific config β Dev vs production settings
- Health checks everywhere β Required for orchestration
Deliver
- working multi-service development environment
- automatic service discovery between services
- centralized telemetry and logging
- cloud-deployment-ready architecture
Validate
- all services start via AppHost
- service discovery resolves correctly
- dashboard shows traces and logs
- health checks pass for all services
- integrations connect without manual config
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.