The goal of the .NET framework is to provide developers with a robust collection of resources for making software applications. Even though .NET was primarily designed for creating desktop software and, to a lesser degree, early online apps, the current emphasis is on creating robust and feature-rich cloud-native web apps that can be deployed on Microsoft’s Azure cloud platform. This year’s conference was primarily about a new offering called .NET Aspire.
Read this article to get a solid grasp of Aspire and why it will be a valuable asset to your developer arsenal.
What Exactly is .NET Aspire?
.NET Aspire is an opinionated, cloud-ready stack for building resilient, observable, and configurable cloud-native applications with .NET. It comes with a pre-built collection of cloud-native components that are improved with features like health checks, telemetry, resilience, and service discovery.
Combined with a sophisticated but simple local developer experience, .NET Aspire makes it easy to discover, acquire, and configure essential dependencies for cloud-native apps on day one and beyond for new and existing .NET apps using .NET 8+.
Key Features and Capabilities
Application Templates: .NET Aspire offers application templates such as the .NET Aspire application and the .NET Aspire starter app, making it easy to create new Aspire .NET 8 applications from Visual Studio or the .NET CLI.
AppHost and ServiceDefaults: The AppHost project orchestrates the running of the application and handles dependencies, while the ServiceDefaults project configures telemetry, logging, metrics, analytics, and more, simplifying the setup of essential components for cloud-native apps.
Blazor Integration: Aspire includes a simple Blazor front-end web application as an optional application template, providing an open-source web framework to build performant web applications using HTML and C#.
Developer Dashboard: Aspire configures and launches a developer dashboard, simplifying debugging by providing logs, links to running web pages, containers, traces, and more.
Benefits of using .NET Aspire
Cloud-Ready Stack: .NET Aspire is designed to build observable, production-ready, and distributed cloud-native applications, making it suitable for deployment in public or private cloud platforms.
Opinionated Configuration: It provides a curated set of components through NuGet packages, handling specific cloud-native concerns, and streamlining the configuration process for developers.
Enhanced Developer Toolkit: .NET Aspire simplifies the process of creating Aspire .NET 8 applications by offering application templates, such as the .NET Aspire application and the .NET Aspire starter app, for easy project scaffolding in Visual Studio or via the .NET CLI.
AppHost and ServiceDefaults Projects: These projects orchestrate the application, handle dependencies, configure telemetry, logging, metrics, analytics, and more, thereby simplifying the setup of essential components for cloud-native apps.
Orchestration and Service Discovery: .NET Aspire simplifies the orchestration of distributed applications, making it easier to deploy an entire set of services and dependencies as a single entity, and handle service discovery and configuration.
Production-Ready Applications: It focuses on making applications easily monitorable and deployable into Docker containers, simplifying the process of pushing applications to production without the need for complex and fragile scripts.
Scalability and Resilience: Aspire addresses the challenge of seamlessly integrating disparate pieces of a system, ensuring the resiliency of the overall application in a distributed environment.
Things To Know While Leveraging .NET Aspire
As DevOps has grown in popularity, developers have often felt pressured to become experts in a wide range of technologies that aren’t directly connected to cloud-native application development.
This is a common situation among modern developers: A developer may not possess the necessary knowledge to answer a basic issue that arises while developing an application, despite its significance to the project.
Aspire is Microsoft’s solution to this problem; it’s a collection of tools, components, services, and sample code that developers can use to build and release cloud-native apps faster.
Here are the five main points about.NET Aspire that you should be familiar with.
Opinionated Components
Here is the list of components that can be added to an Aspire app.
Component | NuGet | Description |
Azure Blob Storage | Aspire.Azure.Storage.Blobs | A library for accessing Azure Blob Storage. |
Azure Cosmos DB Entity Framework Core | Aspire.Microsoft.EntityFrameworkCore.Cosmos | A library for accessing Azure Cosmos DB databases with Entity Framework Core. |
Azure Cosmos DB | Aspire.Microsoft.Azure.Cosmos | A library for accessing Azure Cosmos DB databases. |
Azure Key Vault | Aspire.Azure.Security.KeyVault | A library for accessing Azure Key Vault. |
Azure Service Bus | Aspire.Azure.Messaging.ServiceBus | A library for accessing Azure Service Bus. |
Azure Storage Queues | Aspire.Azure.Storage.Queues | A library for accessing Azure Storage Queues. |
Azure Table Storage | Aspire.Azure.Data.Tables | A library for accessing the Azure Table service. |
PostgreSQL Entity Framework Core | Aspire.Npgsql.EntityFrameworkCore.PostgreSQL | A library for accessing PostgreSQL databases using Entity Framework Core. |
PostgreSQL | Aspire.Npgsql | A library for accessing PostgreSQL databases. |
RabbitMQ | Aspire.RabbitMQ.Client | A library for accessing RabbitMQ. |
Redis Distributed Caching | Aspire.StackExchange.Redis.DistributedCaching | A library for accessing Redis caches for distributed caching. |
Redis Output Caching | Aspire.StackExchange.Redis.OutputCaching | A library for accessing Redis caches for output caching. |
Redis | Aspire.StackExchange.Redis | A library for accessing Redis caches. |
SQL Server Entity Framework Core | Aspire.Microsoft.EntityFrameworkCore.SqlServer | A library for accessing SQL Server databases using Entity Framework Core. |
SQL Server | Aspire.Microsoft.Data.SqlClient | A library for accessing SQL Server databases. |
Many essential services, such as several database connections, Redis, Entity Framework, key management, and more, are immediately available when referring to this list of basic components.
Application Templates
.NET Aspire Application: A basic Aspire application containing the AppHost and ServiceDefaults projects, ideal for scenarios where a Blazor app is not required or when integrating with an existing .NET app.
.NET Aspire Starter App: This template adds a simple “Hello world!” Blazor app to the .NET Aspire Application, suitable for clean-sheet development when a Blazor web app is desired.
Steps to Create .NET Aspire Application
To create a new .NET Aspire Starter Application, you can use either Visual Studio, Visual Studio Code, or the .NET CLI. Here are the steps to create a project for this quickstart:
Using Visual Studio
- Navigate to File > New > Project at the top of Visual Studio.
- Search for Aspire and select .NET Aspire Starter Application in the dialog window. Select Next.
- Enter a Project Name of AspireSample and proceed to the next screen.
Ensure that .NET 8.0 (Long Term Support) is selected and Use Redis for caching (requires a supported container runtime) is checked, then select Create.
Using VS Code
- From a new instance of Visual Studio Code, select Create .NET project button and choose the .NET Aspire Starter Application template.
- Run the command βdotnet new aspire-starter –use-redis-cache –output AspireSampleβ
AppHost, ServiceDefaults, and Blazor in .NET Aspire
AppHost: Orchestrator project that runs all projects in a .NET Aspire application.
ServiceDefaults: Shared project managing configurations reused across app projects for resilience, service discovery, and telemetry.
Blazor: ASP.NET Core Blazor App project with default .NET Aspire service configurations, used for interactive web UI development in C#.
These components streamline app orchestration and configuration, providing a unified debugging experience across different app resources.
Simplified Orchestration With .NET Aspire
The creation and execution of distributed applications are Aspire’s strong suits.
App Model: It is a collection of resources that make up your distributed application, and it includes .NET projects, containers, executables, and cloud resources that your app depends on.
App Host/Orchestrator Project: This is the .NET project responsible for orchestrating all apps within the app model. It runs all the projects that are part of the .NET Aspire project.
Resource: Represents a part of an application, such as a .NET project, container, executable, database, cache, or cloud service.
Reference: Defines a connection between resources, expressed as a dependency using the βWithReferenceβ API.
Service Discovery and Connection String Management: .NET Aspire’s orchestration simplifies the management of cloud-native app’s configuration and interconnections, including service discovery and connection string management.
Cloud-Agnostic Resources: .NET Aspire provides a variety of cloud-agnostic resources through NuGet packages such as Kafka, MongoDB, MySQL, Node.js, PostgreSQL, Redis, and more.
Aspire and Kubernetes are not the same
Keep in mind that Aspire isn’t a replacement for Kubernetes. In fact, Aspire and Kubernetes could coexist in one application.
When it comes to cloud application deployment and running, Aspire is all about orchestration and containers. Kubernetes allows users to manage clusters of containers that are running on several servers. Aspire has the capability to generate a manifest list that can be utilised for Kubernetes deployment.
Kubernetes streamlines container management, making it easier to balance cloud resources, hosting costs, and user or customer experience (UX/CX).
Simply put, you can use Docker containers to develop and operate .NETΒ Aspire apps, and Kubernetes to manage and scale containers in your host environment.
The Developer Dashboard
To make debugging your application easier, Aspire sets up and launches a developer dashboard the moment you run it. There are traces, logs, and links to live web pages and containers on the dashboard.
By publishing the app to an Azure sandbox, you can test it under stress while keeping an eye on the dashboard for any alert flags that would indicate problems in a real multi-session host environment, rather than localhost.
Conclusion
.NET Aspire offers a robust approach to app orchestration and configuration, simplifying the management of complex .NET projects.
Looking to harness the power of .NET for your next project? Techcronus offers cutting-edge .NET development and deployment solutions tailored to your business needs. Whether it’s building scalable web applications, enterprise solutions, or cloud-native apps, our team of experts is ready to bring your vision to life. Get in touch with us today to explore our comprehensive .NET development and deployment services.