.NET Aspire: A Quick Review

.NET Aspire: A Quick Review

Microsoft introduced a new cloud-native application development stack named .NET Aspire (preview). They explain their purpose for producing such a stack as "to make .NET one of the most productive platforms on the planet for building cloud-native applications". By saying cloud-native application, they mean an application that consists of small, interconnected pieces/microservices and consumes various services like databases, messaging, and caching. They also define .NET Aspire as "a cloud-ready stack for building observable, production-ready, distributed applications.

As the idea is to enable developers to build resilient, observable, and configurable cloud-native applications with .NET, they added built-in service discovery, telemetry, resilience, and health checks. They group .NET Aspire's features into three categories: orchestration, components, and tooling.

Orchestration refers to the coordination of elements by managing their configuration. You can build a distributed application, and add your projects (by registering in the DI container) with their service discovery and connection string information. Components are NuGet packages designed to simplify connections to popular services and platforms such as Azure services, Redis, RabbitMQ, or PostgreSQL. For example, if you want to work with Azure Service Bus, you can register the Service Bus Component in the DI container with its c-connection settings and configuration. Tooling refers to built-in project templates that come with .NET Aspire. It comes with two starter templates; .NET Aspire Application and .NET Aspire Starter Application. While the first one contains only essential AppHosts and ServiceDefaults projects, the Starter Application contains UI and API projects in addition to essential projects. The good point about .NET Aspire templates is you can use service defaults so the application will handle both OpenTelemetry, Health Checks, and Service Discovery concerns.

Quick Demo

I couldn't stop myself from doing a demo. To meet the prerequisites list, I installed the VS Preview version (17.9.0) on my computer with .NET Aspire included. I created a new project by choosing .NET Aspire Starter Application. It was exciting to see a distributed application was fully configured and ready to run. It created a solution with four projects in it.

As the startup project, the AppHost project is modeled as the orchestrator project. You can connect and configure different projects and services here. In this example, we can see that ApiService and Web references exist in the AppHost project. The solution's startup project configuration was configured as a Single startup project and the AppHost project was selected. We can say that, as an orchestrator, the AppHost project is responsible for starting registered projects.

Setting the IsAspireHost project property to true makes the AppHost project an orchestrator project.

ServiceDefaults is a shared project that manages the resilience, service discovery, and telemetry configurations that are used by all the projects in your solution. Service Defaults were injected at the top. The .NET Core, gRPC, and HTTP clients were added to the telemetry tracing configuration by default. Exporter structure to export, logs, metrics, and tracing also appeared to be ready to use.

The ApiService is a tiny ASP.NET Core Minimal API project that exposes one endpoint to provide data to the frontend.

The Web project is a frontend application that was created with ASP.NET Core Blazor stack. It depends on the ServiceDefaults project.

When I started the application, a dashboard was created on the specified port and the Web application also started on its preconfigured port.

The Dashboard page lists the included projects with their statuses and shows containers if any. It also presents logs, traces, and metrics.

The Web application was also running and it was fetching weather data from the ApiService properly.

After spending some time on the Web application, I was able to see logs, metrics, and traces on the Dashboard and this was satisfying enough!

I'll spend more time exploring its architectural and design details. It looks great as a starting point. Thanks to the whole team!


Ref: