.NET Aspire provides tools, templates, and packages for building observable, production-ready distributed apps. It is build with a code-first app model, develop locally by using unified tooling, and deploy anywhere on cloud, Kubernetes, or your servers.
Prerequisites
Visual Studio 2022 installed,
Docker desktop installed,
Basics of Asp .Net, Aspire
Source Code
The source code is publicly available on github: Link
Building blocks of .NET Aspire
Smart Defaults
.NET Aspire provides a set of smart defaults for services that are commonly used in .NET applications. These defaults are designed to help you get started quickly and provide a consistent experience across different types of applications. This includes:
Developer Dashboards
The dashboard enables real-time tracking of key aspects of your app, including logs, traces, and environment configurations. It’s designed to enhance the development experience by providing a clear and insightful view of your app’s state and structure.
Key features of the dashboard include:
Real-time tracking of logs, traces, and environment configurations.
User interface to stop, start and restart the resources.
Collects and displays logs and telemetry.
Enhanced debugging with Github copilot
Orchestration
Orchestration in .NET Aspire is all about automating how your microservices are started, scaled, and managed. If you’ve ever struggled with manually writing Dockerfiles or hooking up multiple services in a docker-compose file, this is where .NET Aspire helps.
Service Discovery
Service discovery is the mechanism that allows services to dynamically locate and communicate with each other at runtime. Rather than relying on fixed URLs or ports, services register themselves and are discoverable by name within the Aspire application model.
Service discovery in .NET Aspire makes applications environment-agnostic by removing the need to hardcode or manually switch base URLs across local, development, and production setups. Services communicate using logical names (like "api"), and Aspire dynamically resolves the actual endpoint at runtime using composite schemes such as "https+http://api/", preferring HTTPS and falling back to HTTP when needed. This approach simplifies service-to-service communication, supports cloud-native and containerized deployments, and ensures the same configuration works reliably across different environments.
Integration
Aspire provides the suites of nuget packages to easily connect the cloud-native applications with popular services like databases, caches and messaging platforms. It simplifies configuration, orchestration and automatically observability and health checks.
Integrations are added as NuGet Packages. Almost all the popular platform like SQL Server, PostgreSQL, Redis, Cosmos DB, MySQL, Azure Functions, RabbitMQ, OpenAI, Java, Go etc. are available for the integration via NuGet Packages
Deployment
There two main approaches for the deployment using Azure Developer CLI for Azure integration and generating artifacts for other platforms like kubernetes or Docker Compose.
Two main steps are involved for the deployment.
Publishing (Generating Assets): with aspire publish command, the application model defined in AppHost will be transformed into environment-specific parameterized assets like Docker Compose files or Kubernetes manifests.
Deployment (Applying Changes): The aspire deploy command resolves the parameter and applies the generated artifacts to the target environment.
Step by step: Creating and Deploying the .NET Aspire application
Step 1: Create an Aspire Starter Application
Open Visual Studio 2022, click Create a new project, and select Aspire Starter App.
![]()
Provide a project name and choose a location to save it.
![]()
Once created, Visual Studio generates a solution containing four projects:
AppHost
This is the orchestrator project and the entry point of the entire application when run locally. Its primary function is to define, connect, and configure all the different services and infrastructure resources (like databases or caches) within the solution using C# code instead of complex configuration files.
ServiceDefaults
This is a shared project that centralizes common configurations for cross-cutting concerns like resilience (automatic retries), service discovery, health checks, and telemetry (logging, metrics, and distributed tracing). Other service projects reference this project to inherit these enterprise-ready defaults, ensuring consistency without duplicating code in every service.
ApiService
This project is an ASP.NET Core Minimal API project that provides a backend data source to the frontend. It is a standard service project that consumes the configurations from the ServiceDefaults project.
Web
This project is typically an ASP.NET Core Blazor application (or other frontend types depending on the exact template used) that serves as the user interface. It interacts with the ApiService and also benefits from the shared configurations in the ServiceDefaults project.
Step 2: Run the Application
By default, AppHost is set as the startup project. Run the solution.
![]()
When the application starts, you are redirected to the Aspire Dashboard. Here, you can see the running resources, the API service and the Web application.
The dashboard provides rich observability features, including:
Resources overview
Console output
Structured logs
Distributed traces
Metrics
Step 3: Integrate External Service (Redis) into the Application
To add Redis, right-click on the AppHost project and select Add > .NET Aspire Package.
Search for Redis and install the required package Aspire.Hosting.Redis
Next, update the AppHost configuration to add Redis and Redis Commander, and link it to the API service:
var cache = builder.AddRedis("cache").WithRedisCommander();
var apiService = builder.AddProject<Projects.AspireApp_ApiService>("apiservice")
.WithReference(cache)
.WithHttpHealthCheck("/health");
Step 4: Run and Verify Third party integration Services (Redis)
Run the AppHost project again.
![]()
You will now see two additional services in the Aspire Dashboard:
Both services run automatically in Docker Desktop. If you open Docker Desktop, you can see the Redis containers running.
![]()
By browsing to Redis Commander, you can view, manage, and inspect data stored in Redis using a user-friendly UI.
![]()
Using the same approach as Redis, you can easily integrate other external infrastructure services such as Microsoft SQL Server, PostgreSQL, and message brokers like RabbitMQ. .NET Aspire provides packages for these technologies, allow them to be added to the AppHost with minimal code while automatically handling service discovery, configuration, and local container orchestration.
Cheers !