.NET Aspire
Opinionated stack for building observable, production-ready cloud-native applications with .NET. Aspire simplifies distributed app development with built-in orchestration, service discovery, and telemetry.
Features
Orchestration
- AppHost Project: Coordinate multiple services
- Service Discovery: Automatic service-to-service communication
- Container Support: Redis, PostgreSQL, SQL Server, RabbitMQ, etc.
- Resource Management: Centralized configuration
- Development Dashboard: Monitor all services in one place
Built-in Components
- Redis: Caching and messaging
- PostgreSQL: Database integration
- SQL Server: Microsoft database
- RabbitMQ: Message queuing
- Azure Service Bus: Cloud messaging
- Cosmos DB: NoSQL database
- Blob Storage: Object storage
- And many more...
Observability
- OpenTelemetry: Built-in distributed tracing
- Logging: Structured logging across services
- Metrics: Health checks and performance metrics
- Dashboard: Real-time monitoring UI
- Distributed Tracing: Request flow visualization
Service Defaults
- Health Checks: Automatic endpoint registration
- Service Discovery: DNS-based discovery
- Configuration: Standardized patterns
- Resilience: Built-in retry policies
- Telemetry: Automatic instrumentation
Getting Started
Installation
dotnet workload install aspire
Create New Project
dotnet new aspire-starter -o MyAspireApp
cd MyAspireApp
Project Structure
MyAspireApp/
├── MyAspireApp.AppHost/ # Orchestration
├── MyAspireApp.ServiceDefaults/ # Shared configuration
├── MyAspireApp.ApiService/ # API project
└── MyAspireApp.Web/ # Frontend project
AppHost Example
var builder = DistributedApplication.CreateBuilder(args);
// Add Redis cache
var cache = builder.AddRedis("cache");
// Add PostgreSQL database
var postgres = builder.AddPostgres("postgres")
.WithPgAdmin();
var catalogDb = postgres.AddDatabase("catalogdb");
// Add API service with dependencies
var apiService = builder.AddProject<Projects.MyAspireApp_ApiService>("apiservice")
.WithReference(cache)
.WithReference(catalogDb);
// Add Web frontend
builder.AddProject<Projects.MyAspireApp_Web>("webfrontend")
.WithReference(apiService)
.WithReference(cache);
builder.Build().Run();
Service Integration
Consuming Services
// In ApiService
var builder = WebApplication.CreateBuilder(args);
// Add service defaults (telemetry, health checks, etc.)
builder.AddServiceDefaults();
// Add Redis
builder.AddRedisClient("cache");
// Add PostgreSQL
builder.AddNpgsqlDataSource("catalogdb");
var app = builder.Build();
app.MapDefaultEndpoints(); // Health, metrics, etc.
app.Run();
Using Dependencies
// Inject Redis
public class CatalogService
{
private readonly IConnectionMultiplexer _redis;
public CatalogService(IConnectionMultiplexer redis)
{
_redis = redis;
}
public async Task<Product> GetProductAsync(int id)
{
var db = _redis.GetDatabase();
var cached = await db.StringGetAsync(
quot;product:{id}");
if (cached.HasValue)
return JsonSerializer.Deserialize<Product>(cached!);
// Fetch from database...
}
}
Development Dashboard
Access at http://localhost:15888 (default)
Features
- Resource List: All services and dependencies
- Logs: Aggregated log streaming
- Traces: Distributed trace viewer
- Metrics: Real-time metrics
- Console Output: Live service output
- Environment Variables: Configuration view
Component Integration
Azure Service Bus
var serviceBus = builder.AddAzureServiceBus("messaging");
var apiService = builder.AddProject<Projects.ApiService>("api")
.WithReference(serviceBus);
Blob Storage
var storage = builder.AddAzureStorage("storage");
var blobs = storage.AddBlobs("blobs");
var api = builder.AddProject<Projects.Api>("api")
.WithReference(blobs);
RabbitMQ
var messaging = builder.AddRabbitMQ("rabbitmq")
.WithManagementPlugin();
var worker = builder.AddProject<Projects.Worker>("worker")
.WithReference(messaging);
Deployment
Azure Container Apps
# Install Azure tools
dotnet tool install -g aspirate
# Deploy to Azure
azd init
azd up
Kubernetes
# Generate manifests
aspirate generate
# Deploy to k8s
kubectl apply -f ./aspirate-output/
Docker Compose
# Generate docker-compose
dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer
# Or use built-in manifest generation
Service Defaults
Automatically configured for all services:
Observability
- OpenTelemetry tracing
- Structured logging
- Metrics collection
- Health check endpoints
Resilience
- HTTP client resilience
- Retry policies
- Circuit breakers
- Timeout policies
Configuration
- Environment-based config
- Azure Key Vault integration
- Secret management
- Connection string handling
Best Practices
Development
- Use AppHost for local orchestration
- Leverage service discovery
- Monitor via dashboard
- Test with containers locally
Production
- Deploy via Azure Container Apps or Kubernetes
- Use managed services (Azure Cache for Redis, etc.)
- Configure resilience policies
- Enable Application Insights
Architecture
- Keep services focused and small
- Use message queues for async work
- Implement health checks
- Design for failure
Use Cases
Microservices
- Service orchestration
- Inter-service communication
- Centralized observability
- Development simplification
Cloud-Native Apps
- Container-based deployment
- Scalable architecture
- Modern development practices
- Production-ready defaults
Distributed Systems
- Multiple services coordination
- Message-driven architecture
- Event-driven systems
- Polyglot persistence
Advantages
vs Manual Setup
- Faster: Minutes vs hours for setup
- Standardized: Best practices built-in
- Observable: Telemetry out of the box
- Simplified: Less boilerplate code
vs Docker Compose
- Integrated: Native .NET tooling
- Type-safe: C# configuration
- Intelligent: Service discovery
- Productive: Better dev experience
Components Library
Databases
- PostgreSQL (npgsql)
- SQL Server
- MySQL
- MongoDB
- Cosmos DB
- Oracle
Caching
- Redis
- Valkey
Messaging
- RabbitMQ
- Azure Service Bus
- Kafka
- NATS
Storage
- Azure Blob Storage
- Azure Table Storage
- AWS S3
Monitoring
- Application Insights
- Prometheus
- Seq
Requirements
- .NET 8.0 or later
- Visual Studio 2022 17.9+ or VS Code
- Docker Desktop (for containers)
- Azure subscription (for cloud deployment)
Pricing
- Free: Open source framework
- Cloud Costs: Pay for resources used (Azure, AWS, etc.)
- No Licensing: No Aspire-specific costs
Best For
- Microservices Development: Multi-service coordination
- Cloud-Native Apps: Modern architecture patterns
- .NET Teams: Familiar tooling and patterns
- Startups: Fast, production-ready setup
- Enterprises: Standardized cloud development
Integration
Visual Studio
- Built-in templates
- Debugging support
- Dashboard integration
- IntelliSense support
VS Code
- C# Dev Kit integration
- Debugging capabilities
- Terminal-based workflows
Azure Developer CLI (azd)
- Easy deployment to Azure
- Infrastructure as code
- Environment management
Example Apps
E-commerce
var catalog = builder.AddProject<Projects.Catalog>("catalog")
.WithReference(postgres.AddDatabase("catalogdb"));
var basket = builder.AddProject<Projects.Basket>("basket")
.WithReference(redis);
var ordering = builder.AddProject<Projects.Ordering>("ordering")
.WithReference(serviceBus)
.WithReference(postgres.AddDatabase("orderdb"));
Event-Driven System
var eventBus = builder.AddRabbitMQ("eventbus");
var eventProcessor = builder.AddProject<Projects.EventProcessor>("processor")
.WithReference(eventBus)
.WithReference(database);
var api = builder.AddProject<Projects.Api>("api")
.WithReference(eventBus);
.NET Aspire represents the future of .NET cloud development, making it trivial to build production-ready, observable, distributed applications with minimal ceremony and maximum productivity.
Ready to get started? Visit the official site to learn more.
Visit official site
north_east