
Sign up to save your podcasts
Or


In this post we will build we will build a TODO app from start to finish using Aspire and React.
Source Code
All the code from this post can be found at sayedihashimi/todojsaspire.In this tutorial, we will walk through installing Aspire, but you should have these dependencies installed. You can learn more at Aspire Prerequisites Installing these items will not be covered in this post.
For detailed instructions on getting Aspire, and its dependencies, installed visit
Workload Migration
As of version 9, Aspire no longer requires a separate workload installation. Use dotnet workload list to check installed workloads and dotnet workload uninstall to remove the Aspire workload.Install the new Aspire CLI. The command below will install the tool globally and the dotnet new templates.
On Windows:
On Linux, or macOS:
After installing this tool, you can run it by executing aspire on the command line. You can explore the usage of this tool with aspire -–help. Now that we have the tools installed, let’s move on and create the Aspire app.
Now that the machine is ready with all the prerequisites we can get started.
Let’s create the Aspire app to start with. In VS Code open the command palette
Select the Aspire Starter App template and hit enter.
When prompted for the project name use “TodojsAspire” and select “src” as the destination folder to follow along.
Now that the starter app has been created you should see the following in the Explorer in VS Code. In this case I added the following files before creating the project .gitattributes, .gitignore and LICENSE.
Now would be a good time to execute a build to ensure that there are no build issues.
When using the Aspire Starter App template it will create a few projects including a front-end with ASP.NET Core. Since we are going to use React for the front-end,
After deleting the project we need to remove any references to it. The things that need to be removed include.
In the command palette you can use .NET: Remove Project Reference to delete the reference in TodojsAspire.AppHost. Then delete the following code from the AppHost.cs file in the
Soon we will replace these lines with what is needed to integrate the React app.
To get the API project going, we will first add a model class for the TODO items, and then use dotnet scaffold to generate the initial API endpoints.
Now that we have added the model class, we will scaffold the API endpoints with dotnet scaffold.
We can use dotnet scaffold to generate API endpoints for the Todo model. To install this tool, execute the following command.
When using dotnet scaffold it’s easiest to cd into the project directory and then execute it from there. This tool is interactive by default, to get started execute dotnet scaffold. Make the following selections.
You can see the entire interaction in the following animation.
The following changes were made to the TodojsAspire.ApiService project.
Kick off another build to ensure that scaffolding has worked successfully. If you get any build errors regarding missing packages, ensure that the following packages have been installed.
You can install packages using dotnet add package [PACKAGE NAME].
Open the new file TodoEndpoints.cs so that we can take a look.
This file contains the CRUD methods which are needed to support reading/writing the content from the database.
MoveTaskUp will find the task with a next lower position, and then swaps the position values. This line of code
Now that we have all the database related code ready, we need to create an EF migration. After we create the migration we will integrate the database with the Aspire dashboard.
To create the EF migration, open the terminal in VS Code,
The migrations command will generate a new migration named TodoEndpointsInitialCreate and add it to the project. At this time you would typically also run dotnet ef database update but that isn’t needed in this case.
For SQLite support in the AppHost, we will need to use the Aspire Community Toolkit. Execute the command below in the “src” folder to install SQLite support in the AppHost.
Follow the prompts to add the package. This will add a PackageReference to the AppHost and make other APIs available for the builder.
Open the AppHost.cs file in the TodojsAspire.AppHost project. Replace the contents with the code below.
In AppHost.cs we have added a SQLite database and registered the API service. We called WithReference(db) on the API so that it gets the connection
To configure the ApiService we will need to add the package CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite and update the connection
Modify the Program.cs in the Api project to have the following contents.
The most important changes here are that we changed how the database is being initalized. Previously the connection string was coming from the
Now that we have all the
In the TodojsAspire.ApiService project open the file named TodojsAspire.ApiService.http. If your project doesn’t have a file with that name, create a new one.
For detailed info on the dashboard, see this article
Key features of the dashboard include:
The dashboard will show the projects which have been configured and their status. You can easily navigate to the app, view logs and other important info. This dashboard currently
In the screenshot above, you can see the URLs for the ApiService project. Copy one of the URLs for the ApiService project, we will need that to exercise the app. You can click on the URL for db-sqliteweb to open a web interface to interact with the database, but that isn’t needed for this tutorial.
By default, when you start the AppHost, you will get a new database and the migration(s) will automatically be applied to the database to update it. If you want your local data to persist
Below is the HTTP file, you may need to update the base url variable on the first line to match your project. For more info on HTTP file see the
When you paste the value for the API URL make sure to remove the trailing slash.
With this HTTP file we can exercise the app. It includes requests for most endpoints in the TodoEndpoints class. You can execute the requests with Send Request above the URL line.
To fix the first issue, specifically group.MapGet("/",, update the get endpoint to have the following code.
To fix the issue regarding the missing position value, update the POST method to have the following code.
With this change, when a Todo item is submitted without a value for Position, the value for Position will be set to the max value of Position in the database + 1. Now we have
To create the React project we will use the npm command which is installed with node. Visit Node.js — Download Node.js® to get it installed.
Open a terminal, cd into the src directory and then execute the command below.
When prompted specify the following values.
This will create a new folder named todo-frontend in the src directory and then scaffold the React app into that folder. After the app has been scaffolded, npm will tell you to execute the following commands to initialize the app.
These commands will install the dependencies and run the app to ensure that there are no issues. If you encounter and error, delete the todo-frontend folder and try again. You can
We will use the Aspire CLI to help us integrate the front-end with the AppHost. We will install the node integration package in the
Follow the prompts to add the package.
We will add a Community Toolkit package to add Vite support. Execute the command below.
When prompted select ct-extensions (CommunityToolkit.Aspire.Hosting.NodeJS.Extensions).
project. Add the following to that file before builder.Build().Run();.
This will add the front-end as an app in AppHost project and add integration with the dashboard. Now we need to configure the front-end to consume the port that the
This will configure a proxy so that all commands are routed through the same origin, and it injects the URL for the ApiService. That’s all the changes that are needed to integrate
Troubleshooting Vite.config.js load failure
If you see an error that the vite.config.js file failed to load, run npm install in the todo-frontend folder, then press the play button next to the front-end in the Aspire Dashboard. You shouldn’t need to restart the AppHost.The dashboard should look like the following.
If you click on the todo-frontend URL, you’ll see the default Vite React template in the browser. Now we can start building our front-end. I’ll walk you through all the steps
First let’s add the components that we need for the todo app, and then we will update the files needed to use those components. In the todo-frontend/src folder, add a
This is a basic component that will be used to display the todo item as well as elements for the actions; move up, move down and delete. We will use this component in the TodoList
This component will display the list of todo items in our front-end. It fetches the todo items from the ApiService app, and all actions will be sent to that API for persistence.
This file is straightforward CSS and doesn’t need much explanation for front-end developers. Now that we have added the components, we need to update the app to work with
Update the contents of src/main.jsx in todo-frontend to the code below.
Open App.jsx and replace the content with the following.
Open index.css and replace the contents with the CSS below.
Finally, update the content of index.html to have the content below
Now we have updated the app and it should be working. Start the AppHost project and then click on the URL for the front-end in the dashboard. Below is a video of the app running.
Our app is now working. You can use the dashboard to view telemetry flowing automatically between the database, .NET Web API backend, and React front-end. I didn’t go into much detail on the React code here. I wrote a similar blog post for Visual Studio users which covers the React parts in more details Creating a React TODO app in Visual Studio 2022.
Now that we have the app running locally, the next step would be to deploy this to production. You can deploy this to any web host that supports ASP.NET Core.
In this post, we built a new Aspire app with an ASP.NET Core Web API and connected it to a React front end using JavaScript. We worked entirely from the command line and C# Dev Kit, leveraging the new Aspire CLI and dotnet scaffold to add database support with SQLite.
For feedback on Aspire please file an issue in this repo dotnet/aspire. For feedback related to dotnet scaffold, the correct repo for
The post Building a Full-Stack App with React and Aspire: A Step-by-Step Guide appeared first on .NET Blog.
By In this post we will build we will build a TODO app from start to finish using Aspire and React.
Source Code
All the code from this post can be found at sayedihashimi/todojsaspire.In this tutorial, we will walk through installing Aspire, but you should have these dependencies installed. You can learn more at Aspire Prerequisites Installing these items will not be covered in this post.
For detailed instructions on getting Aspire, and its dependencies, installed visit
Workload Migration
As of version 9, Aspire no longer requires a separate workload installation. Use dotnet workload list to check installed workloads and dotnet workload uninstall to remove the Aspire workload.Install the new Aspire CLI. The command below will install the tool globally and the dotnet new templates.
On Windows:
On Linux, or macOS:
After installing this tool, you can run it by executing aspire on the command line. You can explore the usage of this tool with aspire -–help. Now that we have the tools installed, let’s move on and create the Aspire app.
Now that the machine is ready with all the prerequisites we can get started.
Let’s create the Aspire app to start with. In VS Code open the command palette
Select the Aspire Starter App template and hit enter.
When prompted for the project name use “TodojsAspire” and select “src” as the destination folder to follow along.
Now that the starter app has been created you should see the following in the Explorer in VS Code. In this case I added the following files before creating the project .gitattributes, .gitignore and LICENSE.
Now would be a good time to execute a build to ensure that there are no build issues.
When using the Aspire Starter App template it will create a few projects including a front-end with ASP.NET Core. Since we are going to use React for the front-end,
After deleting the project we need to remove any references to it. The things that need to be removed include.
In the command palette you can use .NET: Remove Project Reference to delete the reference in TodojsAspire.AppHost. Then delete the following code from the AppHost.cs file in the
Soon we will replace these lines with what is needed to integrate the React app.
To get the API project going, we will first add a model class for the TODO items, and then use dotnet scaffold to generate the initial API endpoints.
Now that we have added the model class, we will scaffold the API endpoints with dotnet scaffold.
We can use dotnet scaffold to generate API endpoints for the Todo model. To install this tool, execute the following command.
When using dotnet scaffold it’s easiest to cd into the project directory and then execute it from there. This tool is interactive by default, to get started execute dotnet scaffold. Make the following selections.
You can see the entire interaction in the following animation.
The following changes were made to the TodojsAspire.ApiService project.
Kick off another build to ensure that scaffolding has worked successfully. If you get any build errors regarding missing packages, ensure that the following packages have been installed.
You can install packages using dotnet add package [PACKAGE NAME].
Open the new file TodoEndpoints.cs so that we can take a look.
This file contains the CRUD methods which are needed to support reading/writing the content from the database.
MoveTaskUp will find the task with a next lower position, and then swaps the position values. This line of code
Now that we have all the database related code ready, we need to create an EF migration. After we create the migration we will integrate the database with the Aspire dashboard.
To create the EF migration, open the terminal in VS Code,
The migrations command will generate a new migration named TodoEndpointsInitialCreate and add it to the project. At this time you would typically also run dotnet ef database update but that isn’t needed in this case.
For SQLite support in the AppHost, we will need to use the Aspire Community Toolkit. Execute the command below in the “src” folder to install SQLite support in the AppHost.
Follow the prompts to add the package. This will add a PackageReference to the AppHost and make other APIs available for the builder.
Open the AppHost.cs file in the TodojsAspire.AppHost project. Replace the contents with the code below.
In AppHost.cs we have added a SQLite database and registered the API service. We called WithReference(db) on the API so that it gets the connection
To configure the ApiService we will need to add the package CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite and update the connection
Modify the Program.cs in the Api project to have the following contents.
The most important changes here are that we changed how the database is being initalized. Previously the connection string was coming from the
Now that we have all the
In the TodojsAspire.ApiService project open the file named TodojsAspire.ApiService.http. If your project doesn’t have a file with that name, create a new one.
For detailed info on the dashboard, see this article
Key features of the dashboard include:
The dashboard will show the projects which have been configured and their status. You can easily navigate to the app, view logs and other important info. This dashboard currently
In the screenshot above, you can see the URLs for the ApiService project. Copy one of the URLs for the ApiService project, we will need that to exercise the app. You can click on the URL for db-sqliteweb to open a web interface to interact with the database, but that isn’t needed for this tutorial.
By default, when you start the AppHost, you will get a new database and the migration(s) will automatically be applied to the database to update it. If you want your local data to persist
Below is the HTTP file, you may need to update the base url variable on the first line to match your project. For more info on HTTP file see the
When you paste the value for the API URL make sure to remove the trailing slash.
With this HTTP file we can exercise the app. It includes requests for most endpoints in the TodoEndpoints class. You can execute the requests with Send Request above the URL line.
To fix the first issue, specifically group.MapGet("/",, update the get endpoint to have the following code.
To fix the issue regarding the missing position value, update the POST method to have the following code.
With this change, when a Todo item is submitted without a value for Position, the value for Position will be set to the max value of Position in the database + 1. Now we have
To create the React project we will use the npm command which is installed with node. Visit Node.js — Download Node.js® to get it installed.
Open a terminal, cd into the src directory and then execute the command below.
When prompted specify the following values.
This will create a new folder named todo-frontend in the src directory and then scaffold the React app into that folder. After the app has been scaffolded, npm will tell you to execute the following commands to initialize the app.
These commands will install the dependencies and run the app to ensure that there are no issues. If you encounter and error, delete the todo-frontend folder and try again. You can
We will use the Aspire CLI to help us integrate the front-end with the AppHost. We will install the node integration package in the
Follow the prompts to add the package.
We will add a Community Toolkit package to add Vite support. Execute the command below.
When prompted select ct-extensions (CommunityToolkit.Aspire.Hosting.NodeJS.Extensions).
project. Add the following to that file before builder.Build().Run();.
This will add the front-end as an app in AppHost project and add integration with the dashboard. Now we need to configure the front-end to consume the port that the
This will configure a proxy so that all commands are routed through the same origin, and it injects the URL for the ApiService. That’s all the changes that are needed to integrate
Troubleshooting Vite.config.js load failure
If you see an error that the vite.config.js file failed to load, run npm install in the todo-frontend folder, then press the play button next to the front-end in the Aspire Dashboard. You shouldn’t need to restart the AppHost.The dashboard should look like the following.
If you click on the todo-frontend URL, you’ll see the default Vite React template in the browser. Now we can start building our front-end. I’ll walk you through all the steps
First let’s add the components that we need for the todo app, and then we will update the files needed to use those components. In the todo-frontend/src folder, add a
This is a basic component that will be used to display the todo item as well as elements for the actions; move up, move down and delete. We will use this component in the TodoList
This component will display the list of todo items in our front-end. It fetches the todo items from the ApiService app, and all actions will be sent to that API for persistence.
This file is straightforward CSS and doesn’t need much explanation for front-end developers. Now that we have added the components, we need to update the app to work with
Update the contents of src/main.jsx in todo-frontend to the code below.
Open App.jsx and replace the content with the following.
Open index.css and replace the contents with the CSS below.
Finally, update the content of index.html to have the content below
Now we have updated the app and it should be working. Start the AppHost project and then click on the URL for the front-end in the dashboard. Below is a video of the app running.
Our app is now working. You can use the dashboard to view telemetry flowing automatically between the database, .NET Web API backend, and React front-end. I didn’t go into much detail on the React code here. I wrote a similar blog post for Visual Studio users which covers the React parts in more details Creating a React TODO app in Visual Studio 2022.
Now that we have the app running locally, the next step would be to deploy this to production. You can deploy this to any web host that supports ASP.NET Core.
In this post, we built a new Aspire app with an ASP.NET Core Web API and connected it to a React front end using JavaScript. We worked entirely from the command line and C# Dev Kit, leveraging the new Aspire CLI and dotnet scaffold to add database support with SQLite.
For feedback on Aspire please file an issue in this repo dotnet/aspire. For feedback related to dotnet scaffold, the correct repo for
The post Building a Full-Stack App with React and Aspire: A Step-by-Step Guide appeared first on .NET Blog.