Prerequisites
Before you begin, make sure you have:.NET SDK
.NET SDK
You need .NET 9.0 or later. Check your version:If you need to install or update, visit dotnet.microsoft.com/download.
Container Runtime
Container Runtime
Aspire CLI (will be installed in Step 1)
Aspire CLI (will be installed in Step 1)
The Aspire CLI will be installed in the first step of this quickstart.
Step 1: Install the Aspire CLI
The Aspire CLI provides commands to create, run, and manage Aspire projects.The CLI will automatically add itself to your PATH. You may need to restart your terminal for the changes to take effect.
Step 2: Create Your First Aspire App
Create a new Aspire application using the starter template:The
aspire new command creates a solution with three projects:- AppHost - Orchestrates your app (defines the app model)
- ApiService - A backend API service
- Web - A Blazor web frontend
Step 3: Explore the Project Structure
Let’s look at what was created:The AppHost
OpenAppHost/Program.cs to see how your application is defined:
AppHost/Program.cs
- Creates a Redis cache container
- Adds the API service with a health check
- Adds the web frontend that references both the cache and API
- Sets up dependencies so services start in the right order
The API Service
The API service (ApiService/Program.cs) is a standard ASP.NET Core minimal API with Aspire service defaults:
ApiService/Program.cs
The Web Frontend
The web frontend is a Blazor application that calls the API service. Notice how it uses service discovery:Web/Program.cs
The URL
"https+http://apiservice" uses service discovery. Aspire automatically resolves “apiservice” to the correct URL, preferring HTTPS over HTTP. No hardcoded ports or hosts needed!Step 4: Run Your Application
Start your entire distributed application with a single command:Dashboard Opens Automatically
Your browser will automatically open the Aspire Dashboard. This is your command center for monitoring the application.The dashboard shows:
- Resources: All running services and containers
- Console Logs: Live logs from each resource
- Structured Logs: Searchable, filterable telemetry
- Traces: Distributed traces across service calls
- Metrics: Performance counters and custom metrics
View Running Resources
In the dashboard, click on the Resources tab. You’ll see:
cache(Redis container) - Running on a random portapiservice(.NET project) - Your API servicewebfrontend(.NET project) - Your web frontend
Open the Web Application
Click on the endpoint for
webfrontend or navigate to http://localhost:5174 (the port may vary).You’ll see a Blazor web app showing a weather forecast fetched from the API service.Explore Logs and Traces
In the dashboard:
- Click Console Logs to see live output from all services
- Click Structured Logs to filter and search telemetry
- Click Traces to see the request flow from web → API
Notice you didn’t have to:
- Configure connection strings
- Set up service discovery
- Configure telemetry or logging
- Manage ports manually
Step 5: Make Changes and See Hot Reload
With your app still running, let’s make a change:- Open
ApiService/Program.cs - Change the weather summaries:
ApiService/Program.cs
- Save the file
Step 6: Add a Database
Let’s add a PostgreSQL database to store weather data.- Stop the app (Ctrl+C in your terminal)
-
Open
AppHost/Program.csand add PostgreSQL:
AppHost/Program.cs
- Add the PostgreSQL client integration to your API service:
- Update
ApiService/Program.csto use the database:
ApiService/Program.cs
- Run the app again:
postgres container in the dashboard, and the API service has access to the database connection string automatically!
Understanding What Happened
Automatic Service Discovery
Automatic Service Discovery
When the web frontend references the API service with
client.BaseAddress = new("https+http://apiservice"), Aspire:- Resolves “apiservice” to the actual URL at runtime
- Handles port allocation automatically
- Prefers HTTPS over HTTP when available
- Updates the configuration if services restart on different ports
Configuration Injection
Configuration Injection
When the API service references the database with
builder.AddNpgsqlDataSource("weatherdb"), Aspire:- Injects the connection string as configuration
- Uses the name “weatherdb” to match the resource in AppHost
- Automatically updates if the database container restarts
Dependency Management
Dependency Management
The
.WithReference() and .WaitFor() methods create a dependency graph:Aspire ensures resources start in the correct order and only after their dependencies are ready.Telemetry Configuration
Telemetry Configuration
The
builder.AddServiceDefaults() call adds:- OpenTelemetry exporters that send data to the dashboard
- Structured logging with proper formatting
- Distributed tracing context propagation
- Metrics collection and export
- Health check endpoints
Next Steps
Core Concepts
Learn more about the app model and how resources work
Explore Integrations
Discover 40+ integrations for databases, messaging, and cloud services
Build Real Apps
Follow guides to build production-ready applications
Deploy to Production
Learn how to deploy your Aspire app to Kubernetes or Azure
Common Next Actions
Add More Services
You can add other types of resources to your AppHost:Explore the Dashboard
The Aspire Dashboard is powerful. Try:- Filtering logs by severity or resource
- Following a distributed trace from frontend to backend
- Viewing metrics over time
- Checking environment variables injected into each service
Learn the CLI
Explore other CLI commands:Troubleshooting
Container runtime not found
Container runtime not found
Make sure Docker or Podman is running:If you see an error, start Docker Desktop or Podman Desktop.
Port already in use
Port already in use
If you get a “port already in use” error, Aspire will automatically try other ports. If you need to specify a port:
Dashboard won't open
Dashboard won't open
The dashboard URL is shown in the terminal when you run
aspire run. Copy the URL (including the token) and paste it into your browser.The token is required for authentication during development.Service can't connect to another service
Service can't connect to another service
Make sure you:
- Added
.WithReference()in the AppHost - Used the correct resource name in your service code
- Called
builder.AddServiceDefaults()in your service
Congratulations! You’ve created, run, and explored your first .NET Aspire application. You’re now ready to build more complex distributed applications with ease.