AspiringHeroes

Stars
2

.NET Aspire

.NET Aspire is based on a previous experiment from Microsoft called Project Tye which was release around May 2020.

The goal of .NET Aspire is to improve the local development experience for Distributed Applications (aka microservices). In a nutshell, .NET Aspire helps to improve:

The great thing about a .NET Aspire orchestrated application is that we can add all the Projects / Services and Components that make up our overall microservices system into one project and have a way to describe how the applications are connected or related to each other.

var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedisContainer("cache");
var heroApi = builder.AddProject<Projects.AspiringHeroes_Api>("heroesRestAPI");
var heroGrpc = builder.AddProject<Projects.AspiringHeroes_Grpc>("heroesGrpcService");

builder.AddProject<Projects.AspiringHeroes_Web>("webUI")
    .WithReference(cache)
    .WithReference(heroApi)
    .WithReference(heroGrpc);

builder.Build().Run();

The AppHost and ServiceDefaults is responsible for all configuration that enables the health checking, resiliency, service discovery, telemetry and more.

Figure: Using C# to describe the projects and components in the distributed system and how they are related to each other.

.NET Aspire Dashboard Figure: Aspire Dashboard - Projects View

.NET Aspire Dashboard - Traces Figure: Aspire Dashboard - Traces View

.NET Aspire Dashboard - Traces - details Figure: Aspire Dashboard - Trace Details View

✅ Pros

  • The orchestration is great - one project to start and connect everything is a massive time saver
  • .NET Aspire tooling in Visual Studio is great
    • Quickly add Aspire Components (via nuget package manager)
    • Couple of clicks to add Orchestration support (generates some code for us)
    • All the logs in one place
    • Traces - wow... now we can see exactly how our applications were interacting with each other
  • Deployments with Azure Dev CLI (AZD) is very easy

❌ Cons

  • For local development only (for now?)
    • Would be great to have the same dashboard deployed to Azure
    • Although, with ACA, Azure Monitor, Promethius, Graphana etc. we still get the awesome observability we are used to
  • All projects need to be part of the same solution
  • Couldn't find any way to add .NET Aspire Components or Orchestration from the dotnet CLI
  • No "restart" option available on individual projects
  • No easy scriptable functionality (like Project Tye) to define the startup arguments for individual services - currently discovered via launchSettings.json
  • No deployment / publishing options from Visual Studio (for now it is on purpose)
  • Application Insights not provided OOTB, we need to add it ourselves (see Use Application Insights for .NET Aspire telemetry)

Deployment

.NET Aspire allows for flexible deployment of applications across platforms that support .NET and containers. It generates a manifest file to help deployment tools understand the app's structure, which includes information about the projects and dependant services along with the necessary properties for deployment like environment variables and network bindings.

In summary, .NET Aspire simplifies app deployment across various platforms. It works well with containerized environments and integrates with tools like AZD and Aspirate for a streamlined deployment process.

Deploy to Azure Container Apps (ACA)

Azure Container Apps (ACA) is a great choice for hosting .NET Aspire applications. ACA is a managed environment for running containerised applications on a serverless platform.

The Azure Developer CLI (AZD) is used to generate an Azure Bicep, a language for describing and deploying Azure resources. This is used to provision Azure Container Apps resources needed to host .NET Aspire applications. AZD can also directly deploy the application to Azure Container Apps.

Check out the in-depth guide for how to synthesize the Azure Bicep file that you can use as part of your GitHub workflow / Azure DevOps pipeline to automate everything.

Quick deployment from local to ACA

Using AZD, the steps to get a .NET Aspire application deployed from local to Azure Container Apps can be distilled to the following 3 commands:

azd auth login
azd init
azd up

Quite simple right? Ofcourse we would really want to take it further and use automated CI/CD workflows to do the work for us.

Deploy to Azure Kubernetes Service (AKS)

Azure Kubernetes Service (AKS) is an managed environment for running container applications with advanced networking and orchestration capabilities.

Using the Aspirate tool we can generate Kubernetes Manifest files for each component in our .NET Aspire application and eventually push the application containers to a container registry and then deploy to pods on a AKS/K8s cluster.

For detailed steps on how to deploy your application to AKS/K8s, check out the Deploy .NET Aspire apps to a Kubernetes cluster page from MS Learn (its a lot easier than you think).

Links / Resources