Introduction

In this article, we are going to understand the Aspire framework offered by Microsoft. This newbie in town has got a lot to offer and makes our cloud app development effortless. It is an abstraction around the most common things we do when developing cloud applications and many other things in general. If you are thinking what are the most common things that we do, below is the list.

  1. Communication between multiple APIs
  2. Connection to Caching Services and/or Databases.
  3. Structuring projects such that they can be easily maintained and scaled.
  4. Less coding by reusing code and focusing more on business logic.
  5. Dashboarding to monitor our all API services and everything related and stay updated.

It is designed to solve problems around these 3 principles.

  1. Orchestration: Communication and coordination between various elements of cloud application. Eg. Environment variables, Configurations, communication between multiple projects, etc.
  2. Components: It is a collection of Nuget packages that makes connection with popular services effortless. Eg: Redis, Postgres, SQL Server, Messaging Queues, etc. More details -
  3. Tooling: Structure of projects organized in a way that is extensible, maintainable, and standardized.

Since this is an introductory article, you can dig deeper by following the link below - https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview

Let us learn more by taking a walkthrough and how to use it.

Prerequisite

Licensed/Community

Open Source

I will be showing this demo using the Open Source toolchain.

Walkthrough

The way to consume Aspire is by creating a .NET Project if you start from scratch. There are 2 templates offered for aspire projects.

Template Name Short Name Language Tags What it contains
.NET Aspire Application aspire [C#]

Common/.NET

Aspire/Cloud

Creates a project that is empty
.NET Aspire Starter Application aspire-starter [C#]

Common/.NET

Aspire/Blazor/Web/Web

API/API/Service/Cloud

Creates sample project with sample

UI and API included

Since this is an introductory tutorial, let us create a Starter application i.e. 2nd option from the above table.

Open Source toolchain via dotnet CLI and Visual Studio Code.

Type the below commands using cmd.

dotnet workload update

Stack Trace

No workloads are installed for this feature band. To update workloads installed with earlier SDK versions, include the --from-previous-sdk option.

Updated advertising manifest microsoft.net.sdk.tvos.
Updated advertising manifest microsoft.net.workload.emscripten.current.
Updated advertising manifest microsoft.net.workload.mono.toolchain.net6.
Updated advertising manifest microsoft.net.workload.emscripten.net7.
Updated advertising manifest microsoft.net.workload.mono.toolchain.net7.
Updated advertising manifest microsoft.net.sdk.aspire.
Updated advertising manifest microsoft.net.sdk.maccatalyst.
Updated advertising manifest microsoft.net.workload.mono.toolchain.current.
Updated advertising manifest microsoft.net.workload.emscripten.net6.
Updated advertising manifest microsoft.net.sdk.ios.
Updated advertising manifest microsoft.net.sdk.macos.
Updated advertising manifest microsoft.net.sdk.android.
Updated advertising manifest microsoft.net.sdk.maui.
Downloading microsoft.net.sdk.aspire.manifest-8.0.100.msi.x64 (8.0.0-preview.1.23557.2)
Installing microsoft.net.sdk.aspire.manifest-8.0.100.msi.x64 .... Done

No workloads are installed for this feature band. To update workloads installed with earlier SDK versions, include the --from-previous-sdk option.

Successfully updated workload(s):

dotnet workload install aspire

Common Error: Workload ID aspire is not recognized.

Solution: Update SDK to .NET 8, Link - https://dotnet.microsoft.com/en-us/download/dotnet/8.0

Stack Trace:

Downloading Aspire.Hosting.Sdk.Msi.x64 (8.0.0-preview.1.23557.2)
Installing Aspire.Hosting.Sdk.Msi.x64 .... Done
Downloading Aspire.ProjectTemplates.Msi.x64 (8.0.0-preview.1.23557.2)
Installing Aspire.ProjectTemplates.Msi.x64 .... Done
Downloading Aspire.Hosting.Orchestration.win-x64.Msi.x64 (8.0.0-preview.1.23557.2)
Installing Aspire.Hosting.Orchestration.win-x64.Msi.x64 ........ Done
Downloading Aspire.Hosting.Msi.x64 (8.0.0-preview.1.23557.2)
Installing Aspire.Hosting.Msi.x64 .... Done
Successfully installed workload(s) aspire.
dotnet new aspire-starter

Stack Trace:

The template ".NET Aspire Starter Application" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspire/1.0-third-party-notices for details.
Processing post-creation actions...
Restoring D:\Demo\Demo.sln:
  Determining projects to restore...
  Restored D:\Demo\Demo.ServiceDefaults\Demo.ServiceDefaults.csproj (in 22.11 sec).
  Restored D:\Demo\Demo.ApiService\Demo.ApiService.csproj (in 22.11 sec).
  Restored D:\Demo\Demo.Web\Demo.Web.csproj (in 22.11 sec).
  Restored D:\Demo\Demo.AppHost\Demo.AppHost.csproj (in 24.53 sec).
Restore succeeded.
Restoring D:\Demo\Demo.AppHost\Demo.AppHost.csproj:
  Determining projects to restore...
  All projects are up-to-date for restore.
Restore succeeded.
Restoring D:\Demo\Demo.ServiceDefaults\Demo.ServiceDefaults.csproj:
  Determining projects to restore...
  All projects are up-to-date for restore.
Restore succeeded.
Restoring D:\Demo\Demo.ApiService\Demo.ApiService.csproj:
  Determining projects to restore...
  All projects are up-to-date for restore.
Restore succeeded.
Restoring D:\Demo\Demo.Web\Demo.Web.csproj:
  Determining projects to restore...
  All projects are up-to-date for restore.
Restore succeeded.
code .

Select App Host project and type

dotnet run

Stack Trace:

Building...
info: Aspire.Dashboard.DashboardWebApplication[0]
      Now listening on: http://localhost:15009
info: Aspire.Dashboard.DashboardWebApplication[0]
      OTLP server running at: http://localhost:16101
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: D:\Demo\Demo.AppHost

Overview of the home screen

This dashboard provides an overview of the current state, start time, process ID, source location, and endpoints for each project. The "View" action at the end of each project entry likely allows users to access more detailed information or interact with the project in some way.

Navigation overview

That’s it! Thanks for reading till the end. Please add in comment about how you feel about this article.

Also, please feel free to add your suggestion if you want to know more about this framework so I can more post articles for you.