DEV Community

Cover image for Integrating .NET Aspire with WinampToSpotify Project - 1
Atahan C.
Atahan C.

Posted on

Integrating .NET Aspire with WinampToSpotify Project - 1

First of all, I have a hobby project called WinampToSpotify which helps you transfer your local mp3 folder archieve to spotify as a playlist. I decided to add .Net Aspire to WinampToSpotifyWeb solution. First article will be about adding .Net Aspire to project and second article will be about sending custom metrics to Aspire Dashboard and Prometheus.

What is .Net Aspire?

.NET Aspire is a cloud-native application stack designed to simplify the development of distributed systems in .NET. Introduced at Microsoft's 2024 Build developer conference, it provides a set of tools, templates, and libraries to help developers build and manage interconnected services efficiently. It streamlines cloud-native development by automating service discovery, managing configurations, and handling dependencies between services. It provides NuGet packages for seamless integration with services like Redis and PostgreSQL, complete with built-in telemetry and health checks. Developers benefit from tailored project templates and CLI tools for Visual Studio, along with a web-based dashboard that offers real-time observability through logs, metrics, and distributed tracing, simplifying monitoring and debugging.

Adding Service Defaults

The ASP.NET Core team has been lighting up features for cool features for things like tracing, health checks, and resiliency for years. That’s what Service Defaults does for you. You can just turn on Service Defaults and you’ve got smart logging, health checks, resiliency, etc. based on what the .NET team recommends for ASP.NET Core apps and services. If you want, you can easily edit the Program.cs file in the ServiceDefaults project, but you don’t have to. Just turn it on.

  1. Right-click on the solution and select Add > New Project.
  2. Select the .NET Aspire Service Defaults project template.
  3. Name the project ServiceDefaults (any name would work if you’re feeling creative, but the instructions in this post assume you’re using ServiceDefaults).
  4. Click Next > Create.

Service Defaults

Configure Service Defaults
Add a reference to the ServiceDefaults project in the  WinampToSpotifyWeb  project:

  1. Right-click on the Api project and select Add > Reference. Check the ServiceDefaults project and click OK.
  2. Right-click on the MyWeatherHub project and select Add > Reference.
  3. Check the ServiceDefaults project and click OK.
  4. In WinampToSpotifyWeb  project, update their Program.cs files,adding the following line immediately after their var app = builder.Build(); line:
    app.MapDefaultEndpoints();

  5. In WinampToSpotifyWeb project, update their Program.cs files, adding the following line immediately after their var builder = WebApplication.CreateBuilder(args); line:
    builder.AddServiceDefaults();
    Simplify launch and add a fancy dashboard with AppHost

The AppHost has a lot of great features, but two of my favorite are the solutions to the problems above: it simplifies project launch and it adds an amazing dashboard to monitor and manage my app in my development environment. The best way to understand what it’s doing it to just add it to our solution.

Adding an AppHost project

This is the standard “add project” steps we ran through before with ServiceDefaults, but this time we’re going to pick “.NET Aspire App Host” as the project template. In Visual Studio 2022 or Visual Studio Code with the C# DevKit installed:

  1. Right-click on the solution and select Add > New Project.

  2. Select the .NET Aspire App Host project template.

  3. Name the project AppHost (again, any name would work).

  4. Click Next > Create.

AppHost project

Add project references

  1. Add a reference to the  WinampToSpotifyWeb  projects in the new AppHost project:
  2. Right-click on the AppHost project and select Add > Reference.

Check the WinampToSpotifyWeb  project and click OK.

project reference

Orchestrate the Application

In the AppHost project, update the Program.cs file, adding the following line immediately after the var builder = DistributedApplication.CreateBuilder(args);

var app = builder.AddProject<WinampToSpotifyWeb>("winamptospotifyweb");

We got the dashboard.

.net aspire dashboard

We have Resources Tab,Console Tab for console logs, Structured Tab for structured logs, Traces tab for traces, Metrics tab for metrics.

You can see my code changes on my github repo commit code changes

I will continue article with sending custom metrics to Aspire Dashboard and Prometheus, Grafana.

Top comments (0)