.NET Aspire Getting Started
0 views
Jun 19, 2025
In this quick talk, we will familiarize ourselves with .NET Aspire and add it to existing projects: an ASP.NET Core API with CRUD operation and an ASP.NET MVC application as a Client. Then we will add the .NET Aspire and check its features. Conference Website: https://dotnetconference.com šŗ CSharp TV - Dev Streaming Destination http://csharp.tv š C# Corner - Community of Software and Data Developers https://www.c-sharpcorner.com #CSharpTV #CSharpCorner #LiveShow #dotNet #DotNetConf2025
View Video Transcript
0:00
as you know my name is Coman Uh I'm a software engineer Uh but before that let
0:06
me uh tell you that uh this monitor is
0:12
the Streamyard and this is my laptop which I'm going to present on my laptop
0:17
and visual studio and other stuffs and uh my notes are here So uh if I'm
0:24
looking at this um uh monitor all please excuse me uh
0:30
because I should check the chat and comments So let's get started My name is
0:38
uh Tomron and I'm really happy to be here uh as an speaker for the uh net
0:48
aspire new feature of Microsoft which that's really exciting feature
0:56
So uh in this s uh in this session uh
1:02
I'm going to dive into how to enhance an existing net project by adding uh the
1:10
net aspire So why I'm not going to introduce net aspire or getting started
1:17
by uh net aspire because if you do a little search on the internet YouTube or
1:25
anywhere you will find many resources which all of them are talking about how
1:33
to get started I mean how to create a new project uh in uh with Aspire
1:41
Okay But uh in a real world uh they're not going to start from scratch Uh all
1:49
companies they have their own uh projects right and they are working with
1:55
clean architecture microservices and layer or or even
2:01
simple uh web API MVC blazer or or any
2:06
other uh applications they're not going to delete their projects and stop from
2:13
scratch So the big deal is how can I integrate or
2:21
uh add this new feature net aspire to my
2:26
existing project This is better than starting from scratch
2:32
So uh uh for example for u a sample I I have
2:40
created a project and uh as you can see this is my blog on github.io and this is
2:48
my website which uh most of the time I'm working as a mentor um for uh finding a
2:57
job offer It has uh many steps It's not really easy Uh which
3:05
you can take a look at my website and see uh what we do I'm not alone We have
3:13
we we are a team So but if you want uh technical
3:21
um blog this is my blog and you can see uh my articles also I have a YouTube
3:29
channel which you can uh see my YouTube
3:34
channel uh at this address which I uh
3:41
teach whatever I learn I'm same as everybody else So uh as you can see here
3:50
I have a project a web API project which is
3:56
uh implementing a cro operation for a
4:03
really simple entity called person which has an ID first name and last name It
4:10
doesn't matter You can add more properties more fields to uh entity or
4:17
uh you you can have many other entities It doesn't affect on what we
4:23
are going to do And I have my database context
4:31
here I have the controller which uh implements the uh showing the list of
4:40
people uh showing one person by ID uh
4:47
updating creating delete and other uh operations So and one more thing that
4:55
I'm going to show here here is the connection stream It's my connection
5:01
string And let's see what do we have in the program CS the regular things that
5:10
we usually use in our projects controllers API versioning and uh using swagger and
5:19
registering the database and the other stuffs routing mapping controllers and
5:26
others And the another project that I have is an MVC client project That's an
5:32
MVC which acts as uh client uh and uh
5:38
its responsibility is uh showing or or
5:43
uh interacting with my API project to uh
5:48
make an interface for uh let's say our application So if I
5:58
need to run the application uh I need to
6:04
uh run multiple projects because uh I need to run both projects at the same
6:12
time And then when I press the run button let
6:18
me see where it's going to stop
6:39
Yes Okay great So you can see that I
6:44
have two projects starting One is for my uh API project which is loading
6:53
on 5,01 [Music] uh it's my API project and another one
7:01
is my client application which uh in this case it's an MVC application So
7:09
uh of course you know that uh there are other solutions like using
7:17
docker compose for uh converting my application to docker
7:24
image and running them uh through docker But uh here we now we have something
7:34
like net aspire which it helps to uh manage run uh log
7:44
monitor and many other features to uh make it easy our lives
7:53
So uh in my project I'm using API uh MVC EF
8:00
core as my OM uh but uh we are going to convert this
8:08
project to an Aspire project or let me say uh add Aspire to the current project
8:19
So okay uh we're going to talk about what is
8:24
Aspire and how it helps to developers We are going to add uh net aspire to an
8:32
existing project using visual studio of course and uh we we will see how to use
8:40
pre-built packages in net aspire of course Microsoft provides uh some
8:47
packages but uh they're not complete yet I mean uh we need more
8:54
packages but of course is new and uh we need to wait for other tools to
9:03
integrate with blaspire and we will see how we can use
9:12
uh other tools and technologies that are not integrated with Aspire using uh
9:21
container uh for unsupported tools and then uh I will just mention how to use
9:28
Postgress instead of SQL server I'm using SQL server as a database but at
9:35
the end I will add the uh Postgress uh as a database to uh to see
9:44
how it works So let's see what do we have here Let me stop the
9:54
projects and uh let me show one more thing
9:59
uh from my MBC client Uh of course I have my
10:08
controller which as you can see it represents or returns views for listing
10:18
people for showing the detail of a people creating and update delete and other
10:25
stuffs So and one more thing is service I wrote
10:32
a helper generic HTTP service to communicate with my API
10:40
uh with uh HTTP calls and as you can see I'm using HTTP client factory Here I
10:49
have methods like post async get async
10:56
delete update and send for general
11:02
purpose And if you take a look at my program.cs
11:09
uh I'm configuring the HTTP client here
11:14
uh I named it API and I am setting the base URL Why I'm mentioning these
11:22
details because we're going to uh see some magic stuff or really fantastic uh
11:31
features that Aspire uh gives us As you can see I'm setting the base URL
11:39
from my uh app settings which is local host with port
11:47
5,0001 right so I need to define exact port exact address and if I try to
11:56
change something like the port or the address I need to change everywhere that
12:04
I am using Right So keep in mind this one because we will get back to this and
12:12
the others are the usual books Right
12:18
So now I'm going to decide to add net
12:23
aspire to this existing project uh for this simply I can right click on
12:33
the API project or the other one I start from API project and from the add
12:43
menu select the net aspire orchestrate support when
12:49
I click on this button or on this menu uh a pop-up shows up which This is
12:57
telling that I'm going to add two more projects to your project to your
13:05
solution And let me add this
13:11
in another directory Let's call it [Music]
13:20
Aspire And also to make it
13:25
more [Music] beautiful creating a solution directory
13:33
or folder and put it in here Okay So as you can see this project app host
13:40
project is bold and of course you know that when this is bold it means that my
13:48
entry point or running project is this project
13:55
uh after adding the uh aspire project to
14:02
my project I I I I'm having two more projects One is app host
14:09
and another one is service default App host project acts like an orchestrator
14:18
It means that if you have a database if you have uh an API service if you have a
14:26
client if you have a radius for caching if you have any other services this
14:34
project is responsible for uh
14:39
managing all other services And if you take a look at the program.cs CS of
14:48
appost project That's truly simple It's really simple And you can see that uh by
14:57
using add project extension method I'm adding or it added
15:03
alphabetically to the project my API project
15:09
And you might ask question how it
15:15
uh recognize that I have a project called project underscore
15:23
API It doesn't matter It's uhnet behind the scenes It
15:34
uh recognize your applications your projects that uh the app host is
15:43
referencing to them And currently as you can see I'm just referencing to the API
15:51
project And if I add more
15:56
reference like adding reference to the MVC client
16:02
uh it will recognize it here and let's see just
16:12
for check that currently it's not
16:18
recognizing my MVC client as you can See the here I just have project API the
16:27
project that I uh reference to that one Okay So let's just comment this one and
16:38
reference to MVC client Uh there are multiple ways
16:45
uh one is right clicking on the MVC project and do the same process like
16:53
this add Aspire orchestration support Another one is drag and drop to the uh
17:01
to to the appost project and another one is simply writing
17:09
uh the reference here uh it doesn't matter which way you are doing but I'm
17:16
using uh the menu that
17:22
uh visual studio provides and as you can see it's added to my app host project So
17:32
let's get back to the program.cs project and uncomment
17:40
this and Here you go You can see that MBC client is added to projects list
17:50
Right
17:59
So this is the definition of the projects that
18:04
uh we see here And you can see that the
18:13
uh yeah project pass it's changed Okay no problem So and
18:21
let me call this one
18:27
client and for simplicity let me remove the project from the beginning of that
18:36
Okay So I have two projects One API and another one is the client application
18:44
Okay So uh I can do some more things For example
18:54
for example uh I want to not start the client
19:02
application before starting a E API
19:07
Right for example uh I need to wait I need to wait to run the API project
19:16
Simply I can use wait for and here I
19:23
can give a name like API to this one and
19:28
let's call this
19:34
client by providing or using this extension method I'm telling to my
19:41
application or the data pier that hey wait and do not run the client
19:49
application until the API application is run And also I can do a
20:02
reference to my uh web API project And
20:07
if I need to use another things like the databases the containers or anything
20:14
else simply I can use builder dot add for example
20:21
container which we will see uh next minutes how to use uh
20:30
unsupported tools like or for example your client application is not a net
20:38
application like Blazer or MVC It's a react application So what what should I
20:44
do at that case in that case you can turn your
20:51
uh react application to a docker image and simply use container to run that
21:00
So uh the net aspire is a new feature from
21:08
Microsoft designed to simplify building cloud native distributed applications So
21:16
it's going to uh make us uh make the
21:22
working with cloud um easy Right So it uh and and and
21:31
the good part or important part is that it sits top of the net This is the net
21:41
and the net aspire is going to uh sit on top of the net because it's going to
21:48
wrap up all my application my old application and
21:55
uh and then I can use everything that I was using uh I was using like the
22:03
database the API service the postgress uh caching mechanism
22:10
or messaging system or anything that I was using
22:16
[Music] uh and also as I mentioned uh at the
22:22
beginning it provides some uh packages some uh built-in packages like uh
22:31
postress like radies like EF core but still it needs to be
22:40
uh create more packages because still we have uh some tools and technologies that
22:48
are not supported by uh net aspire and we need to run them with
22:57
containers Okay uh the as the net aspire pillars are uh I mean the important
23:05
parts of a net aspire project is uh the orchestration uh net aspire it manage
23:14
multiple services containers and resources in the development uh
23:21
environment and not just development environment it's uh
23:28
uh personally in our company we are using Aspire in our production
23:36
too Another one is service integrations It offers pre-builtin packages for
23:43
connecting to database to using cache system and cloud
23:49
services For example if you are using Azure monitor you can simply by writing
23:56
two or three lines of code uh you can connect to Azure monitor service to
24:04
monitoring your uh old services Another one is
24:11
observability Uh the dot despire bu bu bu bu bu bu bu bu bu bu bu bu bu bu bu bu bu bu bu bu built-in supports for
24:17
logging tracing and metrics to monitor your app's uh
24:23
health by providing your uh health check
24:28
URL and uh providing the logging system and monitoring system and also it has
24:36
some metrics So
24:44
uh imagine we're working on a project with an API a front end and a database
24:53
Normally we spend time configuring each pieces like connection strings ports
25:01
health checks and other stuffs that Aspire automates this
25:09
Remember I showed that I'm using this URL right i
25:18
showed that I am using this connection string
25:26
right but by using spire all of these are going to be automated I mean I'm
25:35
going to configure to be configured automated So this is really nice It's
25:42
like having a development time system that sets up your
25:47
environment and enforces best practices because I'm not going to write code It
25:55
is implementing all uh codes configurations and other stuffs by
26:01
itself And of course it's using the best practice and led uh it it led me to
26:09
focus on coding not not configuring radius not configuring
26:16
rabbit and cube configuring the postress and other uh tools that I'm
26:23
using for our API and MVC project that you can see it can simply uh simplify
26:32
service discovery It means that uh if you pay attention I didn't do anything I
26:39
just added my project or reference my project to app that's enough and this is
26:48
acting like a service discovery I don't need to use any other package or other
26:56
tools as a service discovery by writing these lines of code It's
27:03
done It's [Music] on And of course it's uh it enhance
27:12
debugging and prepare us for cloud deployment
27:17
uh because uh if you remember I when I ran the
27:25
project uh I had two terminals which I could see the logs of
27:32
my both applications separated in two terminals right but uh and and imagine
27:40
if you have for example 10 API services and two other services one database
27:49
another one for uh radius another one for postgress and other stuffs right
27:57
so how many terminals or logging
28:02
uh output you should check for checking the logs but in netaspire I'm going to have
28:12
uh very simple uh or one place to see
28:18
the logs of all u services So
28:30
uh yeah that's it Uh okay so uh I talked
28:36
about the app host and uh let's see what is service default service fault is
28:42
shared configurations for logging um and telery and uh the other stuffs
28:50
that uh is shared between all applications as you can see I have a uh
28:57
add service defaults here which is uh configuring my services like the service
29:04
discovery like the uh health check like the open telemetry and the others Okay
29:11
So and uh because I'm out of time I'm going to make it
29:17
faster So uh yes this is for health
29:23
check And this one is for live and health URL And for monitoring if you're
29:30
using uh Azure monitor you can simply use this
29:36
one And okay great So
29:44
uh just let me add one or two more things and I will
29:51
uh uh finish my presentation Okay
29:57
uh if you are using uh you know we are not using uhn net all the time we might
30:07
use other services like radius like react like posters like other services
30:15
that are not uh the netbased
30:20
uh tools so what should I do uh for
30:25
those situations uh we can use uh as I mentioned the
30:34
the dot add container and uh use the container right
30:41
so uh or if I'm going to use the radius
30:47
which is supported currently supported by uh Microsoft I can simply just add
30:58
[Music] uh Aspire
31:03
package It's nothing but just uh it's filtering uh the Aspire uh packages
31:12
which you can see that I have the radies I have the Postgress and the other
31:18
stuffs If you want to use this it's really simple You can just you need just
31:25
add the Postgress Let me change the version because I'm using the version
31:35
9 And here we go Builder add Postgress
31:42
See that's simple And also I can add the
31:49
database for example people and of course because I'm using
31:55
SQL server I need to change some configurations in my API project instead
32:01
of using SQL server I need to use Postgress but I'm not going to uh go
32:07
through into this because I'm out of time
32:16
And yeah I think that's it Oh okay So
32:21
for the last part let's run the application to see what
32:26
happens when we
32:32
use net aspire or we add to the project
32:55
previous Okay finally
33:10
Great So this is the dashboard of the net aspire It doesn't matter how many
33:17
services you have Uh you have uh 10 API
33:22
services You have two databases or more You have three clients One in uh React
33:32
one is Blazer one is MVC It doesn't matter All of them are here We list here
33:40
and there is a console tab here which you can see the lots of your uh services
33:49
here and the other ones like the structure the
33:57
uh traces the metrics and I'm not going through this um you can uh do a research
34:07
about And but just for make sure everything works fine which is not going
34:13
to work fine because I didn't change the address Oh it's working But uh it's
34:21
because uh it works with both of them Uh as I
34:28
mentioned in here I don't need to specify the port and the address
34:36
Uh I just need to use the name of my
34:42
service That's enough That's enough And it will uh find out that uh what is my
34:51
service this is the service discovery This is the great feature that
34:59
uh net aspire provides And I'm going to rerun the project to make sure
35:05
everything works [Music]
35:16
fine I just hate to bug you because we're running out of I know
35:22
we started a little late but I just hate to bug you I know you hate me already
35:27
Yeah of course Yeah Yeah Perfect Right So I think that that was very