For creating observable, production-ready distributed applications,.NET Aspire offers tools, templates, and packages. It is developed locally using unified tooling, built using a code-first app approach, and deployed anywhere on your servers, Kubernetes, or the cloud.

Building blocks of .NET Aspire
Smart Defaults

.NET Aspire provides a set of smart defaults for services that are commonly used in .NET applications. These defaults are designed to help you get started quickly and provide a consistent experience across different types of applications. This includes:

  • Telemetry: Metrics, Tracing, Logging
  • Resiliency
  • Health Checks
  • Service Discovery

Developer Dashboards
The dashboard enables real-time tracking of key aspects of your app, including logs, traces, and environment configurations. It’s designed to enhance the development experience by providing a clear and insightful view of your app’s state and structure.

Key features of the dashboard include:

  • Real-time tracking of logs, traces, and environment configurations.
  • User interface to stop, start and restart the resources.
  • Collects and displays logs and telemetry.
  • Enhanced debugging with Github copilot

Orchestration
Orchestration in .NET Aspire is all about automating how your microservices are started, scaled, and managed. If you’ve ever struggled with manually writing Dockerfiles or hooking up multiple services in a docker-compose file, this is where .NET Aspire helps.

Service Discovery
The method that enables services to dynamically find and interact with one another during runtime is called service discovery. In the Aspire application paradigm, services register themselves and may be found by name instead of depending on fixed URLs or ports.

Because service discovery in.NET Aspire eliminates the need to hardcode or manually swap base URLs between local, development, and production configurations, applications become environment-agnostic. Logical names (like "api") are used by services to interact, and Aspire uses composite schemes (like "https+http://api/") to dynamically resolve the actual endpoint at runtime, preferring HTTPS and reverting to HTTP as necessary. This method guarantees that the same configuration functions consistently across many settings, facilitates cloud-native and containerized deployments, and streamlines service-to-service communication.


Integration
Aspire provides the suites of nuget packages to easily connect the cloud-native applications with popular services like databases, caches and messaging platforms. It simplifies configuration, orchestration and automatically observability and health checks.

Integrations are added as NuGet Packages. Almost all the popular platform like SQL Server, PostgreSQL, Redis, Cosmos DB, MySQL, Azure Functions, RabbitMQ, OpenAI, Java, Go etc. are available for the integration via NuGet Packages

Deployment
There two main approaches for the deployment using Azure Developer CLI for Azure integration and generating artifacts for other platforms like kubernetes or Docker Compose.

Two main steps are involved for the deployment.

Publishing (Generating Assets): with aspire publish command, the application model defined in AppHost will be transformed into environment-specific parameterized assets like Docker Compose files or Kubernetes manifests.

Deployment (Applying Changes): The aspire deploy command resolves the parameter and applies the generated artifacts to the target environment.
Step by step: Creating and Deploying the .NET Aspire application

Step 1: Create an Aspire Starter Application
Open Visual Studio 2022, click Create a new project, and select Aspire Starter App.


Provide a project name and choose a location to save it.


Once created, Visual Studio generates a solution containing four projects:

AppHost
This is the orchestrator project and the entry point of the entire application when run locally. Its primary function is to define, connect, and configure all the different services and infrastructure resources (like databases or caches) within the solution using C# code instead of complex configuration files.

ServiceDefaults
This is a shared project that centralizes common configurations for cross-cutting concerns like resilience (automatic retries), service discovery, health checks, and telemetry (logging, metrics, and distributed tracing). Other service projects reference this project to inherit these enterprise-ready defaults, ensuring consistency without duplicating code in every service.

ApiService
This project is an ASP.NET Core Minimal API project that provides a backend data source to the frontend. It is a standard service project that consumes the configurations from the ServiceDefaults project.

Web

This project is typically an ASP.NET Core Blazor application (or other frontend types depending on the exact template used) that serves as the user interface. It interacts with the ApiService and also benefits from the shared configurations in the ServiceDefaults project.

Step 2: Run the Application
By default, AppHost is set as the startup project. Run the solution.


When the application starts, you are redirected to the Aspire Dashboard. Here, you can see the running resources, the API service and the Web application.

The dashboard provides rich observability features, including:

  • Resources overview
  • Console output
  • Structured logs
  • Distributed traces
  • Metrics

Step 3: Integrate External Service (Redis) into the Application
To add Redis, right-click on the AppHost project and select Add > .NET Aspire Package.

Search for Redis and install the required package Aspire.Hosting.Redis

Next, update the AppHost configuration to add Redis and Redis Commander, and link it to the API service:
var cache = builder.AddRedis("cache").WithRedisCommander();

var apiService = builder.AddProject<Projects.AspireApp_ApiService>("apiservice")
    .WithReference(cache)
    .WithHttpHealthCheck("/health");


Step 4: Run and Verify Third party integration Services (Redis)
Run the AppHost project again.


You will now see two additional services in the Aspire Dashboard:
cache: the Redis in-memory data store
rediscommander: a web-based graphical user interface for managing Redis data

Both services run automatically in Docker Desktop. If you open Docker Desktop, you can see the Redis containers running.


By browsing to Redis Commander, you can view, manage, and inspect data stored in Redis using a user-friendly UI.


Other external infrastructure services like Microsoft SQL Server, PostgreSQL, and message brokers like RabbitMQ can be easily integrated using the same methodology as Redis.NET Aspire offers packages for these technologies, enabling their addition to the AppHost with little code while automatically managing service discovery, configuration, and local container orchestration.

HostForLIFE.eu ASP.NET Core 10.0 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.