Back to School Sale! 🎉
Dometrain Pro 20% off with code BTS2025! (Excl. Business and VS Pro)
00
Days
00
Hrs
00
Min
00
Sec
Get Pro 20% off!

Why should you use .NET Aspire?

This tutorial is a written version of one of the lessons of our Getting Started: .NET Aspire course

Getting Started: .NET Aspire thumbnail

Getting Started: .NET Aspire

Get started with .NET Aspire, the future of .NET development

If you've been developing cloud-native applications with .NET, you're familiar with the challenges: orchestrating multiple services, managing dependencies like databases and caches, and trying to get a clear picture of how everything interacts. .NET Aspire is Microsoft's new, opinionated stack designed to solve these exact problems.

Before we dive into a practical codebase, it's worth taking a moment to summarize the key benefits of Aspire. Why should you consider it for your next project? Based on hands-on experience, here are the big, game-changing advantages that make Aspire so compelling.

1. Out-of-the-Box Observability: A Local Dashboard That Changes Everything

For years, getting good observability into a distributed system during local development was a chore. You'd have to spin up a complex stack of tools like Grafana, Prometheus, Jaeger, and Loki, then manually configure everything to talk to each other. Aspire completely changes this.

  • Effortless OpenTelemetry Support: Aspire comes with first-class, out-of-the-box support for OpenTelemetry. This means structured logs, real-time metrics, and distributed traces are available from the moment you run your application.
  • The Aspire Dashboard: All this information is fed directly into a powerful local dashboard that launches with your app. You can see resource usage, filter logs, and inspect metrics without any extra setup.
  • Traces and Spans are a Game Changer: The most impactful feature here is the visualization of traces and spans. Seeing a request's journey through your services in a waterfall view is incredibly insightful. It allows you to pinpoint performance bottlenecks and understand service interactions in a way that sifting through text-based log files never could. In fact, it's so useful that you may find yourself adding custom data to your spans during development as your primary debugging tool, moving away from traditional logging for many scenarios.

2. The "F5 Experience": Simplified Local Development and Onboarding

Aspire's core mission is to streamline the inner-loop development experience. It excels at making the process of running and debugging complex applications as simple as running a single monolith.

  • Launch Everything with One Command: With Aspire, you can run your entire application stack - multiple APIs, a web frontend, databases, and message brokers - with a single F5 press in Visual Studio or by running dotnet run from the AppHost project's directory.
  • Automatic Dependency Management: Aspire automatically spins up any required dependencies defined in your AppHost, including Docker containers for things like Postgres, Redis, and RabbitMQ. There are no separate docker-compose files to manage or scripts to run.
  • Painless Onboarding for New Developers: Think about the experience for a new team member. They can clone the repository, hit F5, and the entire distributed application just works. The databases are running, the services discover each other, and they can start being productive immediately. This friction-free setup is a massive improvement over lengthy and error-prone manual setup guides.

How-To: Experience the Simplicity with the AspireShop Sample

  1. Find the Samples: Search online for "github aspire samples" and go to the official dotnet/aspire-samples repository on GitHub. This repository contains a wealth of examples, including integrations with Azure Functions, JavaScript, Node, and Python.
  2. Clone and Navigate: Clone the repository and use a terminal to navigate to the AspireShop sample's AppHost directory.
    # Clone the repository first
    git clone https://github.com/dotnet/aspire-samples.git
    cd aspire-samples/samples/AspireShop/AspireShop.AppHost
    
  3. Run the App: Execute the dotnet run command.
    dotnet run
    
  4. Explore the Dashboard: Aspire will build the projects, pull and run the necessary Docker images (which might take a moment on the first run), and launch the dashboard in your browser. You'll see all the resources - the Redis cache (basketcache), the Postgres database (postgres), the frontend, and various backend services - spinning up and reporting their status. From there, you can click the URL for the frontend and interact with the fully functional e-commerce site.

3. Seamless Integrations and Service Discovery

The magic that makes this all work is Aspire's concept of integrations and its built-in service discovery.

  • Smart NuGet Packages: Aspire provides specialized NuGet packages for common dependencies (e.g., Aspire.Npgsql for Postgres, Aspire.StackExchange.Redis for Redis). These packages do two key things:
    1. They orchestrate running the dependency in a local container during development.
    2. They wrap the underlying .NET client library, automatically adding health checks, telemetry, and best practices.
  • No More Connection Strings: Because these components hook into Aspire's service discovery, your application services can find dependencies without hardcoded connection strings in your appsettings.json. Aspire injects the configuration at runtime, which means wiring up a connection to Redis or a database often becomes a simple one-line setup in your Program.cs file. This greatly simplifies configuration management between local development and deployed environments.

A Note on Deployment

While the benefits for local development are clear and immediate, it's worth noting that the deployment story for Aspire is still evolving. Aspire can generate manifests for deployment to environments like Azure Container Apps or Kubernetes.

However, if you already have mature DevOps patterns and deployment pipelines in place, you may not need to use Aspire's deployment features right away. You can gain enormous value by using Aspire only for its local development story and continuing to use your existing deployment methods. The two are not mutually exclusive, and this pragmatic approach allows you to adopt the best parts of Aspire today without overhauling your entire CI/CD process.

In summary, Aspire's primary, game-changing value lies in its ability to dramatically improve the local development experience through built-in observability, a simplified "F5" workflow, and seamless service integration.

This tutorial is a written version of one of the lessons of our Getting Started: .NET Aspire course

Getting Started: .NET Aspire thumbnail

Getting Started: .NET Aspire

Get started with .NET Aspire, the future of .NET development