update first-mono-app to .NET 10#37104
Conversation
| * Federation Gateway | ||
|
|
||
| > [!IMPORTANT] | ||
| > [Duende Software](https://duendesoftware.com/) might require you to pay a license fee for production use of Duende Identity Server. |
| 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> |
There was a problem hiding this comment.
Updated the example to use a primary constructor.
| ## 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/) |
There was a problem hiding this comment.
Technically 6.0.5 would still work, but I updated this to the latest version.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
I used a MapGroup to group the endpoints.
Because it's a minimal API, I removed the /api prefix from the endpoints.
| 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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I think keep the "Configure JSON serialization options" section for these two reasons:
- 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.
- 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: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Copilot pointed out that there's an outdated reference to WeatherForecast. This is also updated in the v9 version.
| * <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/) |
There was a problem hiding this comment.
This was the closest training module I could find to minimal api's.
|
@timdeschryver, thanks again for taking this on! For the question on brackets for placeholders. Yes, this below is the latest guildeline to follow: 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. |
|
Code snippets links for v9 are resulting in build errors: |

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?
Internal previews