Skip to content

update first-mono-app to .NET 10#37104

Open
timdeschryver wants to merge 2 commits intodotnet:mainfrom
timdeschryver:issue/37075
Open

update first-mono-app to .NET 10#37104
timdeschryver wants to merge 2 commits intodotnet:mainfrom
timdeschryver:issue/37075

Conversation

@timdeschryver
Copy link
Copy Markdown
Contributor

@timdeschryver timdeschryver commented May 5, 2026

Closes #37075
See comments for some more info about the changes.

If required, I can also provide a .NET 11 example (there won't be an impact on this example so far AFAIK).

Additionally, I noticed copilot providing the following feedback, should I also change this?

Several placeholders use angle-bracket style (for example, <port>, <user>, <version_number>, <data_directory_path>) instead of the required brace placeholder style.

Use this pattern for placeholders: {PLACEHOLDER NAME} (uppercase words, spaces allowed inside braces).

Specific bad vs good examples:

Bad: https://localhost:<port>/openapi/v1.json
Good: https://localhost:{PORT}/openapi/v1.json

Bad: C:\Users\<user>\AppData\Local\Programs\mongosh
Good: C:\Users\{USER NAME}\AppData\Local\Programs\mongosh

Bad: C:\Program Files\MongoDB\Server\<version_number>\bin
Good: C:\Program Files\MongoDB\Server\{VERSION NUMBER}\bin

Bad: mongod --dbpath <data_directory_path>
Good: mongod --dbpath {DATA DIRECTORY PATH}

Internal previews

📄 File 🔗 Preview link
aspnetcore/tutorials/first-mongo-app.md Create a web API with ASP.NET Core and MongoDB

* Federation Gateway

> [!IMPORTANT]
> [Duende Software](https://duendesoftware.com/) might require you to pay a license fee for production use of Duende Identity Server.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same body, except the migration part.
I can revert this if you want, I just thought it didn't add any value since that was for earlier .NET versions.

Image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!

Comment on lines +9 to +14
public class BooksService(IOptions<BookStoreDatabaseSettings> bookStoreDatabaseSettings)
{
private readonly IMongoCollection<Book> _booksCollection = new MongoClient(bookStoreDatabaseSettings.Value.ConnectionString)
.GetDatabase(bookStoreDatabaseSettings.Value.DatabaseName)
.GetCollection<Book>(bookStoreDatabaseSettings.Value.BooksCollectionName);
// </snippet_ctor>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the example to use a primary constructor.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

## Prerequisites

* [MongoDB 6.0.5 or later](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/)
* [MongoDB 8.0.0 or later](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically 6.0.5 would still work, but I updated this to the latest version.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest stable + supported is good. 8.0.0 is good.

* [ReplaceOneAsync](https://mongodb.github.io/mongo-csharp-driver/2.14/apidocs/html/M_MongoDB_Driver_IMongoCollection_1_ReplaceOneAsync.htm): Replaces the single document matching the provided search criteria with the provided object.

## Add a controller
## Create endpoints
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used a MapGroup to group the endpoints.
Because it's a minimal API, I removed the /api prefix from the endpoints.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

To satisfy the preceding requirements, make the following changes:

1. In `Program.cs`, chain the following highlighted code on to the `AddControllers` method call:
1. In `Program.cs`, add the following highlighted code:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I think the section "Configure JSON serialization options" doesn't add much value here, and I would suggest to remove it from the article.
That being said, the code is updated to follow the minimal API way of configuring the serialization options.

Copy link
Copy Markdown
Contributor

@wadepickett wadepickett May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keep the "Configure JSON serialization options" section for these two reasons:

  1. Common real-world need: When working with MongoDB, property name mismatches between C# (PascalCase) and JSON (camelCase) are something developers frequently encounter. Showing how to configure JsonOptions and use [JsonPropertyName] is practical.
  2. The minimal API approach is different enough to be worth showing.

That said, it could be condensed a bit.

Your update looks good to me, thanks!

The `[JsonPropertyName]` attribute's value of `Name` represents the property name in the web API's serialized JSON response.

1. Add the following code to the top of `Models/Book.cs` to resolve the `[JsonProperty]` attribute reference:
1. Add the following code to the top of `Models/Book.cs` to resolve the `[JsonPropertyName]` attribute reference:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot pointed out this should be JsonPropertyName, I also updated the v9 version.


The app uses the OpenAPI document generated by OpenApi, located at `/openapi/v1.json`, to generate the UI.
View the generated OpenAPI specification for the `WeatherForecast` API while the project is running by navigating to `https://localhost:<port>/openapi/v1.json` in your browser.
View the generated OpenAPI specification for the `BookStoreApi` API while the project is running by navigating to `https://localhost:<port>/openapi/v1.json` in your browser.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot pointed out that there's an outdated reference to WeatherForecast. This is also updated in the v9 version.

Comment thread aspnetcore/tutorials/first-mongo-app.md Outdated
* <xref:web-api/index>
* <xref:web-api/action-return-types>
* [Create a web API with ASP.NET Core](/training/modules/build-web-api-aspnet-core/)
* [Create a web API with ASP.NET Core](/training/modules/interact-api/)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the closest training module I could find to minimal api's.

@wadepickett
Copy link
Copy Markdown
Contributor

wadepickett commented May 5, 2026

@timdeschryver, thanks again for taking this on!

For the question on brackets for placeholders. Yes, this below is the latest guildeline to follow:
Use this pattern for placeholders: {PLACEHOLDER NAME} (uppercase words, spaces allowed inside braces).
Bad: https://localhost:/openapi/v1.json
Good: https://localhost:{PORT}/openapi/v1.json

For .NET 11: if you would like to provide a .NET 11 version that sounds great. Not required though! I don't think there would be much of a difference at all, but .NET 11 and VS are still a potential moving target until the release.

At the moment the only articles we are actively updating are ones effected by .NET 11 related features or feature changes that need to be represented as a priority.

@wadepickett
Copy link
Copy Markdown
Contributor

Code snippets links for v9 are resulting in build errors:
Line 168: [Warning] The code snippet "first-mongo-app/samples_snapshot/9.x/Book.cs" could not be found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minimal API with MongoDB: Update for .NET 10, VS 2026, latest VS, MongoDB 8.5 redo for Min API

2 participants