Discovering the Gem in .NET 8: Introducing ".NET Aspire"
Tags: dotnet, dotnet8, cloudnative, newfeature
Published: 2023-12-18 10:54:43

This year, Microsoft rolled out a game-changer in the .NET 8 lineup – ".NET Aspire." As a developer, this has quickly become my absolute favorite feature. 

 We'll delve into the essentials of ".NET Aspire" and walk through the installation steps to get it up and running on your development environment. From there, we'll fire up a new project, leveraging the power and flexibility that ".NET Aspire" brings to the table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inos24xhiekn7a2n0txe.png)
**What is .net Aspire?**
Imagine a toolkit designed specifically for crafting cloud-ready, distributed applications. That's exactly what .NET Aspire brings to the table. It's not just a set of tools; it's a cloud-native stack delivered through NuGet packages, addressing key concerns in modern application development.

The beauty of .NET Aspire lies in its compatibility with the microservices approach. If you're into building applications with smaller, interconnected components, this is your golden ticket. Cloud-native apps, leveraging .NET Aspire, seamlessly consume various services like databases, messaging, and caching.

**Before we dive into the world of ".NET Aspire," let's make sure you're all set. Here's your checklist:

**.NET 8 Installed**: It's like the superhero suit for your development adventures. Make sure you have .NET 8 ready to roll on your machine.

.**NET Aspire Workload**: 
 CLI to install .net aspire
  
```
dotnet workload update
// to make sure latest .net aspire installed
```
```
dotnet workload install aspire
//This brings all the magic to your development world.
```
```
dotnet workload list
//check current aspire version
```
**IDE or Code Editor**: Choose your weapon! While it's optional, having a good Integrated Developer Environment (IDE) or code editor enhances the experience. You can go with Visual Studio 2022 Preview version 17.9 or higher for the full superhero vibe. If you're more of a minimalist, Visual Studio Code works like a charm too.
**Docker Desktop:**
For that extra oomph in containerized magic, grab "Docker Desktop."


**Launching Your First .NET Aspire Project: Easy-Peasy Steps**!

Ready to dip your toes into the world of ".NET Aspire"? Let's create your very own project with these simple commands:

Basic .NET Aspire Project:
If you're starting fresh, use this magic line:

```
dotnet new aspire --name dotnet8Aspire

```
This sets up a basic ".NET Aspire" project for you – like a blank canvas waiting for your code masterpiece.

Fancy .NET Aspire Project (with UI and API):
Feeling a bit adventurous? Try this one:
```
dotnet new aspire-starter
```
This not only creates a ".NET Aspire" project but also throws in a sample UI and API.

I'm creating basic .net aspire project with out UI and API, I'll add project later.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhdj3l6ly86auu2f4cw8.png)


With the simple command dotnet new aspire, you're getting a no-frills ".NET Aspire" app. What's inside? Just two main things:

**AppHost**: The Maestro of Your App
The AppHost is like the chief conductor of your app orchestra. It rounds up all your projects, builds them, and sets the stage for your application. Imagine it as the leader making sure everyone plays in harmony. As you add more projects, AppHost takes care of the coordination, handling dependencies, NuGet files, and resolving connections – making your life easier.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljlf0inxv7xdp2egunev.png)


**ServiceDefaults**: The Powerhouse of Aspire
Meet ServiceDefaults the powerhouse of Aspire. It's like a pre-loaded magic box for your app. Telemetry, logging, metrics, analytics – it's all set up without you lifting a finger. Microsoft gives you a default set of tools, but hey, feel free to tweak, add, or remove as you please. It's your app, your rules! 🎉💻✨

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ly7443mgxcgbmmfdfgqf.png)


Let's run the project

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u14v943k0uys0ivaqesp.png)

running on port http://localhost:18888


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7hnjzqbmeqm47fo40l6c.png)

Dasboard for .net aspire simple project. Since we've added any project so it's saying no project found on project list.
Lets add simple API project on this aspire project.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ngzm2ftj2f12xf0fwnqb.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4046u4bgz6tmor31nbm1.png)

I've created a simple asp.net core web api project with name dotnet8Aspire.API

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2gz9xvdj6q5nc5y15f1w.png)

Let's add API project to aspire. Since i've not install vs tools for visual studio through which we can enable aspire support for projects with Visual studio with just couple of click. So I'll manually add project to aspire.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dv9lwjjqt6kx5d4z2iw7.png)

API project reference is added on aspire project , now let's configure on appHost program.cs.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3qrbpfk83gvz3pb748e.png)

When we add reference of other projects on aspire , all the added projects will available inside namespace "**projects**"

On API project "dotnet8Aspire.API" add reference of ServiceDefaults project and register AddServiceDefault on program.cs.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oip8bv8rr5ybgomaqyd0.png)

Now Lets run the project again

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6hpi9882d7qur14gesd.png)

as we can see there's our newly added project on dashbaord. We can run the projects from here, view logs, enviroment variables and so on.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxnf00zy7k6zmuxiiv23.png)

API project is running on http://localhost:5244. By regsitering on AppHost (aspire) we don't have to manually run API project, all the things are taken care from appHost.

let's send request from API and see logs from dashboard http://localhost:5244


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gyveigqo0ppu88rka1yi.png)



I've execute one endpoint of API , now let's see on dashboard if there's any logs available from this current request.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avh4vika0je05z20mjpg.png)


And there you have it – a simple sneak peek into the world of ".NET Aspire." This was just the tip of the iceberg, a basic intro to get your feet wet. I hope you found it helpful and maybe learned a thing or two.
 There's so much more to explore in the realm of .NET Aspire. So buckle up, stay curious, and keep an eye out for the next tutorial where we'll dive even deeper into the wonders of .NET Aspire. Until then, happy coding, and may your apps aspire to greatness! 💻🚀🌟