Skip to content

Commit cb3764f

Browse files
authored
Merge pull request #51213 from lootle1/MR124
Technical Review 1058625: Use databases in a .NET Aspire project
2 parents 05a5a05 + 5a843a5 commit cb3764f

12 files changed

+59
-59
lines changed

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/exercise-use-databases-persist-data-from-aspire-app.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ title: Exercise - Use database services to persist data from a .NET Aspire proje
55
metadata:
66
title: Exercise - Use database services to persist data from a .NET Aspire project
77
description: "In this exercise, you see how to add PostgreSQL and MongoDB database integrations to an existing app built with .NET Aspire."
8-
ms.date: 3/20/2024
9-
author: camsoper
10-
ms.author: casoper
8+
ms.date: 07/02/2025
9+
author: IEvangelist
10+
ms.author: dapine
1111
ms.topic: unit
1212
ms.custom:
1313
- sfi-ropc-nochange

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/includes/exercise-use-databases-persist-data-from-aspire-app.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Install the .NET Aspire workload using the .NET CLI:
5353
You should see the details of the .NET Aspire workload.
5454
5555
```console
56-
Installed Workload Id Manifest Version Installation Source
56+
Installed Workload Id Manifest Version Installation Source
5757
---------------------------------------------------------------------------------------------
5858
aspire 8.0.0/8.0.100 SDK 8.0.300-preview.24203, VS 17.10.34902.84
5959
@@ -132,15 +132,15 @@ Two projects connect to the SQLite database, the **Catalog.Data.Manager** and **
132132
1. In **Solution Explorer**, right-click the **Catalog.API** project, select **Add** > **.NET Aspire package**.
133133
1. In the **Search** box, add **Npgsql.EntityFramework** to the end, and press <kbd>Enter</kbd>.
134134
1. On the left, in the results, select **Aspire.Npgsql.EntityFrameworkCore.PostgreSQL**.
135-
1. On the right, select the version dropdown and then select the latest **8.0.0** release.
135+
1. On the right, select the version dropdown and then select the latest **9.3.1** release.
136136
1. Select **Install**.
137137
1. If the **Preview Changes** dialog appears, select **Apply**.
138138
1. In the **License Acceptance** dialog, select **I Accept**.
139139
1. In **Solution Explorer**, select the **Catalog.API** project to view the content of the *Catalog.API.csproj* file.
140140
1. Delete the `PackageReference` for **Microsoft.EntityFrameworkCore.Sqlite**:
141141
142142
```xml
143-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
143+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
144144
```
145145
146146
## Register the new PostgreSQL DbContext
@@ -203,7 +203,7 @@ The **AppHost** project can create a PostgreSQL database container, seed it with
203203
1. In **Solution Explorer**, right-click the **eShop.AppHost** project, select **Add** > **.NET Aspire package**.
204204
1. In the **Search** box, add **PostgreSQL** to the end, and press <kbd>Enter</kbd>.
205205
1. On the left, in the results, select **Aspire.Hosting.PostgreSQL**.
206-
1. On the right, select the version dropdown and then select the latest **8.0.0** release.
206+
1. On the right, select the version dropdown, and then select the latest **9.3.1** release.
207207
1. Select **Install**.
208208
1. If the **Preview Changes** dialog appears, select **Apply**.
209209
1. In the **License Acceptance** dialog, select **I Accept**.
@@ -270,7 +270,7 @@ The current app uses Redis as an in-memory data store for a customer's shopping
270270
271271
1. In **Solution Explorer**, right-click the **Basket.API** project, select **Add**, and then select **Add**>**.NET Aspire package**.
272272
1. In the **Search** box, enter **MongoDB** at the end, and press <kbd>Enter</kbd>.
273-
1. Select the **Aspire.MongoDB.Driver**, and then select the latest **8.0.0** version.
273+
1. Select the **Aspire.MongoDB.Driver**, and then select the latest **9.3.1** version.
274274
1. Select **Install**.
275275
1. If the **Preview Changes** dialog appears, select **Apply**.
276276
1. In the **License Acceptance** dialog, select **I Accept**.@
@@ -358,7 +358,7 @@ The basket microservice uses `HostingExtensions` to manage the Redis data store.
358358
359359
1. In **Solution Explorer**, right-click the **eShop.AppHost** project, and select **Add** > **.NET Aspire package**.
360360
1. In the **Search** box, enter **MongoDB** at the end, and press <kbd>Enter</kbd>.
361-
1. Select the **Aspire.Hosting.MongoDB** package, and then select the latest **8.0.0** version.
361+
1. Select the **Aspire.Hosting.MongoDB** package, and then select the latest **9.3.1** version.
362362
1. Select **Install**.
363363
1. If the **Preview Changes** dialog appears, select **Apply**.
364364
1. In the **License Acceptance** dialog, select **I Accept**.@

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/includes/introduction.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ At the end of this module, you'll be able to:
1111
- Describe the database systems that .NET Aspire can connect to using built-in integrations.
1212
- Use .NET Aspire integrations to read and write data to PostgreSQL, MySQL, and Microsoft SQL Server databases.
1313
- Use .NET Aspire integrations to read and write data to MongoDB databases.
14-
- Understand the basics of testing in .NET Aspire.
15-
- Create a test project using xUnit.
16-
- Write and run tests for .NET Aspire projects.
17-
- Utilize the .NET Aspire testing project templates.
14+
- Understand the basics of testing in .NET Aspire.
15+
- Create a test project using xUnit.
16+
- Write and run tests for .NET Aspire projects.
17+
- Utilize the .NET Aspire testing project templates.

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/includes/store-data-sql-databases.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ In the app host project:
2020

2121
- Install the .NET Aspire hosting integration to the app host project.
2222
- Register a database and create a container for it in the solution's app host.
23-
- Pass a reference to the projects that needs access to the created container hosting the database.
23+
- Pass a reference to the projects that need access to the created container hosting the database.
2424

2525
In the projects that use the database:
2626

@@ -114,12 +114,12 @@ Once the database is registered in the consuming project, you can interact with
114114
public class YourService(NpgsqlDataSource dataSource)
115115
{
116116
public async Task<IEnumerable<Catalog>> GetCatalog()
117-
{
117+
{
118118
const string query = "SELECT * FROM catalog";
119119
using var dbConnection = dataSource.OpenConnection();
120120
var results = await dbConnection.QueryAsync<Catalog>(command);
121121
return queryResult.ToArray();
122-
}
122+
}
123123
}
124124
```
125125

@@ -129,17 +129,17 @@ Or you can then retrieve the database context `YourDbContext` to interact with t
129129
public class YourService(YourDbContext context)
130130
{
131131
public async Task<IEnumerable<Catalog>> GetCatalog()
132-
{
132+
{
133133
var items = await context.ObjectItems;
134134
if (item is null)
135135
{
136136
return Results.NotFound();
137137
}
138-
else
139-
{
140-
return items;
141-
}
142-
}
138+
else
139+
{
140+
return items;
141+
}
142+
}
143143
}
144144
```
145145

@@ -171,7 +171,7 @@ Then in the configuration file, you can add the connection string:
171171

172172
### Using configuration providers
173173

174-
.NET Aspire has a feature of integrations that allows them to support a `Microsoft.Extensions.Configuration`. The PostgreSQL integration supports this feature, and by default it looks for settings using the `Aspire:Npgsql` key. In projects using *appsettings.json*, an example configuration might look like this:
174+
.NET Aspire has a feature of integrations that allows them to support a `Microsoft.Extensions.Configuration`. The PostgreSQL integration supports this feature, and by default it looks for settings using the `Aspire:Npgsql` key. In projects using _appsettings.json_, an example configuration might look like this:
175175

176176
```json
177177
{
@@ -186,7 +186,7 @@ Then in the configuration file, you can add the connection string:
186186
}
187187
```
188188

189-
The previous configuration is setting the connection string, enabling health checks, tracing, and metrics for the PostgreSQL integration. You code then no longer needs to specify the connection string, just use `builder.AddNpgsqlDataSource();`.
189+
The previous configuration is setting the connection string, enabling health checks, tracing, and metrics for the PostgreSQL integration. Your code then no longer needs to specify the connection string, just use `builder.AddNpgsqlDataSource();`.
190190

191191
If you're using the PostgreSQL Entity Framework Core integration, you can use the `Aspire:Npgsql:EntityFrameworkCore:PostgreSQL` key to configure the database context:
192192

@@ -296,7 +296,7 @@ As before, if you use the same database name in app host and the consuming proje
296296

297297
### Using configuration providers
298298

299-
The SQL Server integration also supports `Microsoft.Extensions.Configuration`. By default, it looks for settings using the `Aspire:SqlServer:SqlClient` key. In projects using *appsettings.json*, an example configuration might look like this:
299+
The SQL Server integration also supports `Microsoft.Extensions.Configuration`. By default, it looks for settings using the `Aspire:SqlServer:SqlClient` key. In projects using _appsettings.json_, an example configuration might look like this:
300300

301301
```json
302302
{
@@ -323,10 +323,10 @@ builder.AddSqlServerClient("sqldata", static settings => settings.HealthChecks =
323323

324324
You can pass any of the supported options:
325325

326-
* `ConnectionString`: The connection string of the SQL Server database
327-
* `HealthChecks`: A boolean value that indicates whether the database health check is enabled
328-
* `Tracing`: A boolean value that indicates whether the OpenTelemetry tracing is enabled
329-
* `Metrics`: A boolean value that indicates whether the OpenTelemetry metrics are enabled
326+
- `ConnectionString`: The connection string of the SQL Server database.
327+
- `HealthChecks`: A boolean value that indicates whether the database health check is enabled.
328+
- `Tracing`: A boolean value that indicates whether the OpenTelemetry tracing is enabled.
329+
- `Metrics`: A boolean value that indicates whether the OpenTelemetry metrics are enabled.
330330

331331
### Connect to multiple databases
332332

@@ -380,7 +380,7 @@ var myService = builder.AddProject<Projects.MyService>()
380380
```
381381

382382
Like the PostgreSQL integration, the MySQL integration also allows you to create a container for database management tools. The previous example adds **PhpMyAdmin** to the solution.
383-
383+
384384
## Using a MySQL database
385385

386386
The pattern is the same in the projects that need MySQL access. In the _Program.cs_ file, this code registers the database:
@@ -429,7 +429,7 @@ builder.AddMySqlDataSource("MySqConnection");
429429
### Configuration providers
430430

431431
The `Aspire:MySqlConnector` key is used to configure the MySQL integration.
432-
432+
433433
```json
434434
{
435435
"Aspire": {
@@ -508,6 +508,6 @@ if (app.Environment.IsDevelopment())
508508
}
509509
```
510510

511-
The above code checks the state of the app environment. If it's in development, the code retrieves the `CatalogContext` class and runs the `EnsureCreated` method. This method creates the database and runs any migrations that are pending.
511+
The code checks the state of the app environment. If it's in development, the code retrieves the `CatalogContext` class and runs the `EnsureCreated` method. This method creates the database and runs any migrations that are pending.
512512

513513
For more information on how to seed the different database integrations, see the [.NET Aspire documentation](/dotnet/aspire/database/seed-database-data).

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/includes/test-aspire-projects.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
Testing is an essential part of developing high-quality software. Testing can help you find and fix bugs, improve performance, and ensure that your code meets the requirements and expectations of your users. Testing can also help you automate the deployment process and prevent regressions in the future. .NET Aspire provides tools and libraries to simplify the development, testing, and deployment of distributed applications.
22

3-
In this unit, you learn how to test .NET Aspire projects using xUnit, a popular testing framework for .NET. You learn how to create different types of tests, such as integration tests and functional tests, and how to run them using the .NET Aspire CLI or Visual Studio.
3+
In this unit, you learn how to test .NET Aspire projects using xUnit, a popular testing framework for .NET. You learn how to create different types of tests, such as integration tests and functional tests, and how to run them using the .NET Aspire CLI or Visual Studio.
44

5-
## Create a test project
5+
## Create a test project
66

77
The easiest way to create a .NET Aspire test project is to use the testing project template. You can use the `dotnet new` command to create a standard class library project, and then add the references to the .NET Aspire testing libraries and the xUnit packages.
88

99
```dotnetcli
1010
dotnet new aspire-xunit
1111
```
1212

13-
## Explore the test project
13+
## Explore the test project
1414

1515
The following example test project was created as part of the **.NET Aspire Starter Application** template. If you're unfamiliar with it, see [Quickstart: Build your first .NET Aspire project](/dotnet/aspire/get-started/build-your-first-aspire-app). The .NET Aspire test project takes a project reference dependency on the target app host. Consider the template project:
1616

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/index.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
### YamlMime:Module
22
uid: learn.use-databases-dotnet-aspire-app
33
metadata:
4-
title: Use databases in a .NET Aspire project
4+
title: Use Databases in a .NET Aspire Project
55
description: "Learn about the database systems that .NET Aspire can connect to using built-in integrations. Then see how to configure connections to, and store data in, relational and nonrelational databases."
6-
ms.date: 3/20/2024
7-
author: camsoper
8-
ms.author: casoper
6+
ms.date: 07/02/2025
7+
author: IEvangelist
8+
ms.author: dapine
99
manager: coxford
1010
ms.topic: module
1111
ms.service: aspnet-core

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/introduction.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ title: Introduction
44
metadata:
55
title: Introduction
66
description: "Introduction"
7-
ms.date: 3/20/2024
8-
author: camsoper
9-
ms.author: casoper
7+
ms.date: 07/02/2025
8+
author: IEvangelist
9+
ms.author: dapine
1010
ms.topic: unit
1111
durationInMinutes: 1
1212
content: |

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/knowledge-check.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ title: Module assessment
44
metadata:
55
title: Module assessment
66
description: "In this unit, answer questions about the knowledge you gained in this module."
7-
ms.date: 3/20/2024
8-
author: camsoper
9-
ms.author: casoper
7+
ms.date: 07/02/2025
8+
author: IEvangelist
9+
ms.author: dapine
1010
ms.topic: unit
1111
module_assessment: true
1212
durationInMinutes: 2
@@ -28,10 +28,10 @@ quiz:
2828
choices:
2929
- content: "Connection strings in the appsettings.json file and inline code."
3030
isCorrect: false
31-
explanation: "That's incorrect. These two ways are supported but there are more."
31+
explanation: "That's incorrect. These two ways are supported, but there are more."
3232
- content: "With inline code and using Microsoft.Extensions.Configuration."
3333
isCorrect: false
34-
explanation: "That's incorrect. These two ways are supported but there are more."
34+
explanation: "That's incorrect. These two ways are supported, but there are more."
3535
- content: "Using Microsoft.Extensions.Configuration, connection strings, and inline code."
3636
isCorrect: true
3737
explanation: "That's correct. All of these ways are supported."

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/store-data-nosql-databases.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ title: Store data in NoSQL databases
55
metadata:
66
title: Store data in NoSQL databases
77
description: "Learn how to use .NET Aspire integrations to read and write data to MongoDB databases."
8-
ms.date: 3/20/2024
9-
author: camsoper
10-
ms.author: casoper
8+
ms.date: 07/02/2025
9+
author: IEvangelist
10+
ms.author: dapine
1111
ms.topic: unit
1212
ms.custom:
1313
- sfi-ropc-nochange

learn-pr/aspnetcore/use-databases-dotnet-aspire-app/store-data-sql-databases.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ title: Store data in SQL-compliant databases
55
metadata:
66
title: Store data in SQL-compliant databases
77
description: "Learn how to use .NET Aspire integrations to read and write data to PostgreSQL, MySQL, and Microsoft SQL Server databases."
8-
ms.date: 3/20/2024
9-
author: camsoper
10-
ms.author: casoper
8+
ms.date: 07/02/2025
9+
author: IEvangelist
10+
ms.author: dapine
1111
ms.topic: unit
1212
ms.custom:
1313
- sfi-ropc-nochange

0 commit comments

Comments
 (0)