Turn your card into code with Klutchcard (Sponsored)
What if your credit card had an API?
With Klutchcard, developers create unlimited virtual cards, auto-pause subscriptions, cap spend per merchant, and stream real transaction data straight into their own tools.
Build dashboards, test payments safely, or automate budgets β without relying on third-party fintechs.
Klutchcard provides clear docs, Postman collections, and real examples.
.NET Aspire is an application framework for building observable, production-ready, cloud-native applications with .NET.
It provides a consistent way to manage your application's dependencies, configuration, and deployment.
Think of Aspire as a layer that sits on top of your application and orchestrates how everything works together.
It handles service discovery, configuration, health checks, and telemetry out of the box.
Starting from version 13, .NET Aspire was rebranded to Aspire and is now a multi-language application platform.
While Aspire continues to provide best-in-class support for .NET applications, version 13.0 brings support for Python and JavaScript.
It provides comprehensive support for running, debugging, and deploying applications written in these languages.
Today, I want to show you how to build and run a .NET application with Aspire 13 and .NET 10.
The WithReference(cache) and WithReference(postgres) methods inject connection strings for Redis and PostgreSQL into the API project.
Aspire automatically sets environment variables that the API can read to connect to these resources.
Step 6:
Configure the connection strings in the Products.Api project to connect to the PostgreSQL database:
The key part is configuration.GetConnectionString("postgres"). This reads the connection string that Aspire injected when we called WithReference(postgres) in AppHost.cs.
Aspire automatically sets an environment variable with the PostgreSQL connection string, and the configuration system reads it.
This way, you don't need to hardcode connection strings in appsettings.json or your own environment variables.
In this project, I use the regular EF Core NuGet packages for Npgsql:
Microsoft.EntityFrameworkCore 10.0.0
Microsoft.EntityFrameworkCore.Design 10.0.0
Npgsql.EntityFrameworkCore.PostgreSQL 10.0.0
Step 7:
Configure the connection string in the Products.Api project to connect to the Redis cache:
The AddHybridCache method registers HybridCache with default expiration settings.
The AddRedis method registers StackExchangeRedisCache as the L2 cache.
Just like with PostgreSQL, Aspire injects the Redis connection string via configuration.GetConnectionString("cache").
In this project, I use the following NuGet packages for Redis cache:
This declares a Redis resource named "cache". The WithRedisInsight() method adds RedisInsight, a web-based GUI for inspecting Redis data.
When you run the app, Aspire starts a Redis container and a RedisInsight container. You can browse to RedisInsight from the Aspire dashboard to view cached keys and values.
By default, Aspire configures OpenTelemetry to send logs and metrics to the dashboard.
But you can configure to send logs and traces to any other destination, such as Jaeger, Seq, Grafana or any other observability tool.
By default, OpenTelemetry is configured with AspNetCore and HttpClient instrumentation.
For our project, we need to add instrumentation for the PostgreSQL and Redis integrations.
What I like about the Aspire is how easy it is to deploy your application to various locations.
Let's explore how we can deploy our app to Docker Compose.
First, we need to install the following NuGet package into the AppHost project:
bash
1dotnet add package Aspire.Hosting.Docker
Second, we need to add the following code to the AppHost.cs:
AddDockerComposeEnvironment tells Aspire to use a Docker Compose environment named "env".
The WithExternalHttpEndpoints() method makes the API accessible from outside the Aspire environment.
This is needed to run the application in Docker from the created Docker Compose file.
With a single Aspire CLI command, we can deploy our application to a Docker Compose YAML file:
bash
1aspire publish -o docker-compose-artifacts
As a result, Aspire will generate two files in the docker-compose-artifacts folder:
.env - Environment variables for the Docker Compose environment
docker-compose.yaml - Docker Compose file that defines the services and their dependencies
Here is what the generated docker-compose.yaml file looks like:
Simplified local development: Run all your services, databases, and dependencies with a single command.
Built-in observability: OpenTelemetry integration for logs, metrics, and traces comes preconfigured.
Service discovery: Services automatically discover each other without hardcoded URLs.
Configuration management: Centralized configuration that works locally and in the cloud.
Easy deployment to Docker Compose and Cloud: Deploy your entire application stack to Docker, Azure or AWS with minimal setup.
Consistent developer experience: New team members can get the entire application running in minutes.
Aspire 13 makes it easy to deploy your application to Azure.
You can use the azd (Azure Developer CLI) tool to provision Azure resources and deploy your app to Azure Container Apps.
Aspire automatically generates the necessary infrastructure-as-code files (Bicep templates) based on your AppHost configuration.
Simply run azd init to initialize the Azure deployment configuration, then azd up to provision resources and deploy your application.
Aspire will create Azure Container Apps for your API, Azure Database for PostgreSQL, and Azure Cache for Redis, all wired together with the same connection strings and service discovery you used locally.
If you want to learn more about how to deploy your .NET applications to Azure, I recommend reading this article.
Hope you find this newsletter useful. See you next time.
You can download source code for this newsletter for free
Covers everything: C#, ASP.NET Core, EF Core, system design β answer each question first, reveal the solution, and a test after every chapter proves it stuck. Finish, and you earn a verifiable certificate for your LinkedIn.
Not sure where you stand? Take the free .NET Developer Level Test:
Find out your real level β Junior to Senior+
15 minutes across 13 areas of C#, .NET, ASP.NET Core and System Design
No credit card required. When completed you get a personalized report: your level, your strongest areas, and where to focus next β the perfect way to benchmark yourself before diving into the Playbook.