.NET Aspire makes it a lot simpler to develop, deploy, and monitor a microservices resolution – and it’s up to date at a quick tempo.
Now .NET Aspire 9.2 is launched!
With this replace tempo, my guide is just not standing behind. The books repository of Pragmatic Microservices with C# and Azure is repeatedly up to date as effectively.
Different than simply updates, I’m additionally including new .NET Aspire options which completely match effectively to the Codebreaker resolution.
Let’s dive into what’s modified with the latest variations, and the way this enhances the books pattern resolution.
> On this article collection, we’ll discover the newest updates in .NET Aspire 9.2 and the way they improve microservices growth. We’ll take a look at particular enhancements and new options via the lens of the Codebreaker utility, which serves as the primary instance in my guide Pragmatic Microservices with C# and Azure. The primary article covers the primary a part of the guide: Creating Microservices with .NET.
.NET Aspire Variations at quick tempo
What does quick tempo imply in regard to .NET Aspire? After the preliminary launch of .NET Aspire (model 8.0) on Might 21, 2024, new variations have been added each few month (https://github.com/dotnet/aspire/releases?WT.mc_id=DT-MVP-10160):
- Might 21, 2024 – 8.0 – preliminary launch
- Jul 23, 2024 – 8.1
- Aug 29, 2024 – 8.2
- Nov 13, 2024 – 9.0
- Feb 25, 2025 – 9.1
- Apr 10, 2025 – 9.2
> Whereas .NET Aspire itself is updating at a quick tempo and doesn’t supply LTS or STS assist size, .NET Aspire can be utilized with .NET 8 (LTS) and .NET 9 (STS)!
To make it simpler to assist that quick modifications, i switched the books repository to Central Package deal Administration:
Central Package deal Administration
The repository now makes use of Central Package deal Administration (CPM). Now not, a venture specifies the variations of the packages used. As a substitute, the widespread file Dirctory.Packages.props
(which is positioned within the root folder of the repository) specifies the variations of all packages. This made it quite a bit simpler to replace to .NET Aspire 9.0, 9.1, and 9.2!
After updating packages in a single file, breaking modifications nonetheless have to be mounted with all initiatives.
After all, there’s one chapter which doesn’t use CPM. In chapter 1, the place we take a look at what’s within the templates creating .NET Aspire initiatives, CPM is just not used. That is finished through the use of a Listing.Packages.props
file within the folder of the chapter (Listing.Packages.props
):
false
Chapter 1 – Introduction to .NET Aspire and Microservices
provides an introduction of .NET Aspire, and what’s in regards to the utility we develop.
Whereas introducing .NET Aspire, the Codebreaker resolution is launched as effectively.
You’ll be able to check out utilizing a Blazor consumer utility to entry the backend service at Codebreaker Blazor App.
Let’s take a look at how these ideas are carried out in follow.
Chapter 2 – Minimal APIs – Creating REST Providers
Whereas the primary chapter talks about what’s going to be constructed within the guide, with the second chapter we begin constructing the primary service of the entire resolution.
The video games API service is a REST API constructed utilizing ASP.NET Core minimal APIs.
Constantly up to date with .NET Aspire is the dashboard. This reveals the Assets view with .NET Aspire 9.2:
Fully new with .NET Aspire 9.2 is the Graph view:
With chapter 2 we simply see a single service (the icons are new with .NET Aspire as effectively), however this improves with chapter 3.
With our API service in place, the subsequent step is so as to add knowledge persistence.
Chapter 3 – Writing Knowledge to Relational and NoSQL Databases
Chapter 3 provides persistence. Video games and recreation strikes are saved in relational and NoSQL databases.
The guide contains utilizing EF Core with SQL Server and Azure Cosmos DB.
Azure Cosmos DB
Utilizing Docker an Azure Cosmos DB emulator is obtainable – and the preview model doesn’t have the problems the older model had (Codebreaker.AppHost/Program.cs
):
cosmos = builder.AddAzureCosmosDB("codebreakercosmos")
.RunAsPreviewEmulator(p =>
p.WithDataExplorer()
.WithDataVolume("codebreaker-cosmos-data")
.WithLifetime(ContainerLifetime.Session));
Now it’s additionally attainable to create the database and the container with the app mannequin (Codebreaker.AppHost/Program.cs
):
var cosmosDB = cosmos
.AddCosmosDatabase("codebreaker")
.AddContainer("GamesV3", "/PartitionKey");
As a substitute of utilizing the earlier API AddDatabase
, AddCosmosDatabase
returns IResourceBuilder
, which permits to proceed with different APIs equivalent to making a container throughout the database. The container created is configured with the container title, and the partition key title.
Working the appliance with the DataStore
set to Cosmos
, .NET Aspire affords a hierarchical view. GamesV3 is an Azure Cosmos DB container, codebreaker the title of the database which is within the hierarchy of an Azure Cosmos DB account.
The Docker container additionally incorporates the Azure Cosmos DB Knowledge Explorer, which is obtainable with the hyperlink:
The graph view now reveals all these sources in relation:
Utilizing the HTTP recordsdata obtainable with the video games API venture (prolonged utilizing variables to entry the response), it’s straightforward to ship requests, and watch the saved knowledge with the Azure Cosmos DB Knowledge Explorer:
PostgreSQL
To permit utilizing a relational database on a ARM CPU, I’ve added PostgreSQL as a supplier – and included PgAdmin (Codebreaker.AppHost/Program.cs
):
var postgres = builder.AddPostgres("postgres")
.WithDataVolume("codebreaker-postgres-data")
.WithPgAdmin(r =>
{
r.WithImageTag("newest");
r.WithImagePullPolicy(ImagePullPolicy.At all times);
r.WithUrlForEndpoint("http", u => u.DisplayText = "PG Admin");
})
.AddDatabase("CodebreakerPostgres");
By default, with .NET Aspire 9.2, WithPgAdmin
pulls the picture dpage/pgadmin4
with the tag 9.1.0
. This picture is usually up to date – extra typically than .NET Aspire. To get the newest model, r.WithImageTag("newest")
pulls the picture with the newest tag, and that is all the time pulled, utilizing the coverage ImagePullPolicy.At all times
.
Working the appliance with the DataStore
set to Postgres
, PG Admin is proven with the PostgreSQL Admin hyperlink:
The graph view reveals the relations with the totally different sources. The gameapis service accesses the CodebreakerPostgres database operating in a Docker container postgres.
This container is accessed from the postgres-pgadmin useful resource.
Opening pgAdmin, the video games could be adopted by opening the CodebreakerPostgres database:
With our backend providers configured, we will now deal with creating libraries for consumer functions.
Chapter 4 – Creating Libraries for Consumer Purposes
Chapter 4 contains making a library for the consumer utility in two totally different variants: one utilizing the HttpClient
class instantly, which incorporates making a library to focus on a number of .NET variations, and one other library which makes use of Microsoft Kioata, a command-line device to create the consumer code based mostly on the OpenAPI definition.
A console consumer utility is created right here to play the video games. With this chapter, .NET Aspire is used for the backend. Within the following chapter, one other service is created to make use of the consumer library. This consumer utility then enhances the entire resolution and provides one other useful resource to the .NET Aspire app mannequin which we’ll take a look at subsequent.
Abstract
On this first a part of our collection on .NET Aspire 9.2 updates, we’ve coated vital enhancements in creating microservices:
- The brand new Graph view within the .NET Aspire dashboard gives a transparent visualization of service relationships
- Enhanced Azure Cosmos DB emulator assist with preview options and automated container creation
- With Codebreaker, a brand new PostgreSQL integration with PgAdmin and customizable picture settings
- Higher useful resource visualization with new icons and hierarchical views
- Simplified bundle administration utilizing CPM
These updates make it simpler than ever to develop and handle microservices with .NET Aspire. The Codebreaker utility demonstrates these options in motion, from creating REST APIs to implementing knowledge persistence with each NoSQL and relational databases.
The subsequent half, Internet hosting and Deploying covers extra nice .NET Aspire enhancements, such because the aspire CLI!
Do you already use .NET Aspire? Did you learn the guide? Wanting ahead to your feedback!
For extra info: