-
Notifications
You must be signed in to change notification settings - Fork 24.8k
update first-mono-app to .NET 10 #37104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+837
−56
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f99dc6
update first-mono-app to .NET 10
timdeschryver 5ead0f3
reword to minimal web api
timdeschryver a803a31
update placeholder format
timdeschryver bde56b3
correct v9 source paths
timdeschryver bfd66bf
file renames
timdeschryver 8abe57b
file renames
timdeschryver 5412026
Apply suggestion from @wadepickett
wadepickett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ASP.NET Core Identity adds user interface (UI) login functionality to ASP.NET Core web apps. To secure web APIs and SPAs, use one of the following: | ||
|
|
||
| * [Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) | ||
| * [Duende Identity Server](https://docs.duendesoftware.com) | ||
|
|
||
| Duende Identity Server is an OpenID Connect and OAuth 2.0 framework for ASP.NET Core. Duende Identity Server enables the following security features: | ||
|
|
||
| * Authentication as a Service (AaaS) | ||
| * Single sign-on/off (SSO) over multiple application types | ||
| * Access control for APIs | ||
| * Federation Gateway | ||
|
|
||
| > [!IMPORTANT] | ||
| > [Duende Software](https://duendesoftware.com/) might require you to pay a license fee for production use of Duende Identity Server. | ||
|
|
||
| For more information, see the [Duende Identity Server documentation (Duende Software website)](https://docs.duendesoftware.com). | ||
Large diffs are not rendered by default.
Oops, something went wrong.
518 changes: 518 additions & 0 deletions
518
aspnetcore/tutorials/first-mongo-app/includes/first-mongo-app-9.md
Large diffs are not rendered by default.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
aspnetcore/tutorials/first-mongo-app/samples/10.x/BookStoreApi/BookStoreApi.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.7" /> | ||
| <PackageReference Include="MongoDB.Driver" Version="3.8.0" /> | ||
| <PackageReference Include="NSwag.AspNetCore" Version="14.7.1" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
23 changes: 23 additions & 0 deletions
23
aspnetcore/tutorials/first-mongo-app/samples/10.x/BookStoreApi/BookStoreApi.http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| @BookStoreApi_HostAddress = https://localhost:56874 | ||
|
|
||
| GET {{BookStoreApi_HostAddress}}/books | ||
|
|
||
| ### | ||
|
|
||
| @id=string | ||
| GET {{BookStoreApi_HostAddress}}/books/{{id}} | ||
|
|
||
| ### | ||
|
|
||
| POST {{BookStoreApi_HostAddress}}/books | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| //Book | ||
| } | ||
|
|
||
| ### | ||
|
|
||
| DELETE {{BookStoreApi_HostAddress}}/books/{{id}} | ||
|
|
||
| ### |
26 changes: 26 additions & 0 deletions
26
aspnetcore/tutorials/first-mongo-app/samples/10.x/BookStoreApi/Models/Book.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // <snippet_UsingSystemTextJsonSerialization> | ||
| using System.Text.Json.Serialization; | ||
| // </snippet_UsingSystemTextJsonSerialization> | ||
| using MongoDB.Bson; | ||
| using MongoDB.Bson.Serialization.Attributes; | ||
|
|
||
| namespace BookStoreApi.Models; | ||
|
|
||
| public class Book | ||
| { | ||
| [BsonId] | ||
| [BsonRepresentation(BsonType.ObjectId)] | ||
| public string? Id { get; set; } | ||
|
|
||
| // <snippet_BookName> | ||
| [BsonElement("Name")] | ||
| [JsonPropertyName("Name")] | ||
| public string BookName { get; set; } = null!; | ||
| // </snippet_BookName> | ||
|
|
||
| public decimal Price { get; set; } | ||
|
|
||
| public string Category { get; set; } = null!; | ||
|
|
||
| public string Author { get; set; } = null!; | ||
| } |
10 changes: 10 additions & 0 deletions
10
...e/tutorials/first-mongo-app/samples/10.x/BookStoreApi/Models/BookStoreDatabaseSettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace BookStoreApi.Models; | ||
|
|
||
| public class BookStoreDatabaseSettings | ||
| { | ||
| public string ConnectionString { get; set; } = null!; | ||
|
|
||
| public string DatabaseName { get; set; } = null!; | ||
|
|
||
| public string BooksCollectionName { get; set; } = null!; | ||
| } |
98 changes: 98 additions & 0 deletions
98
aspnetcore/tutorials/first-mongo-app/samples/10.x/BookStoreApi/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // <snippet_UsingModels> | ||
| using BookStoreApi.Models; | ||
| // </snippet_UsingModels> | ||
| // <snippet_UsingServices> | ||
| using BookStoreApi.Services; | ||
| // </snippet_UsingServices> | ||
|
|
||
| // <snippet_JsonOptions> | ||
| // <snippet_BooksService> | ||
| // <snippet_BookStoreDatabaseSettings> | ||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| // Add services to the container. | ||
| builder.Services.Configure<BookStoreDatabaseSettings>( | ||
| builder.Configuration.GetSection("BookStoreDatabase")); | ||
| // </snippet_BookStoreDatabaseSettings> | ||
|
|
||
| builder.Services.AddSingleton<BooksService>(); | ||
| // </snippet_BooksService> | ||
|
|
||
| builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options => | ||
| { | ||
| options.SerializerOptions.PropertyNamingPolicy = null; | ||
| }); | ||
| // </snippet_JsonOptions> | ||
|
|
||
| // Add services to the container. | ||
| // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi | ||
| builder.Services.AddOpenApi(); | ||
|
|
||
| // <snippet_UseSwagger> | ||
| var app = builder.Build(); | ||
|
|
||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.MapOpenApi(); | ||
| app.UseSwaggerUi(options => | ||
| { | ||
| options.DocumentPath = "/openapi/v1.json"; | ||
| }); | ||
| } | ||
| // </snippet_UseSwagger> | ||
|
|
||
| // <snippet_MapEndpoints> | ||
| var booksGroup = app.MapGroup("/books"); | ||
|
|
||
| booksGroup.MapGet("/", async (BooksService booksService) => | ||
| { | ||
| var books = await booksService.GetAsync(); | ||
| return Results.Ok(books); | ||
| }); | ||
|
|
||
| booksGroup.MapGet("/{id:length(24)}", async (string id, BooksService booksService) => | ||
| { | ||
| var book = await booksService.GetAsync(id); | ||
|
|
||
| return book is null ? Results.NotFound() : Results.Ok(book); | ||
| }); | ||
|
|
||
| booksGroup.MapPost("/", async (Book newBook, BooksService booksService) => | ||
| { | ||
| await booksService.CreateAsync(newBook); | ||
|
|
||
| return Results.Created($"/books/{newBook.Id}", newBook); | ||
| }); | ||
|
|
||
| booksGroup.MapPut("/{id:length(24)}", async (string id, Book updatedBook, BooksService booksService) => | ||
| { | ||
| var book = await booksService.GetAsync(id); | ||
|
|
||
| if (book is null) | ||
| { | ||
| return Results.NotFound(); | ||
| } | ||
|
|
||
| updatedBook.Id = book.Id; | ||
|
|
||
| await booksService.UpdateAsync(id, updatedBook); | ||
|
|
||
| return Results.NoContent(); | ||
| }); | ||
|
|
||
| booksGroup.MapDelete("/{id:length(24)}", async (string id, BooksService booksService) => | ||
| { | ||
| var book = await booksService.GetAsync(id); | ||
|
|
||
| if (book is null) | ||
| { | ||
| return Results.NotFound(); | ||
| } | ||
|
|
||
| await booksService.RemoveAsync(id); | ||
|
|
||
| return Results.NoContent(); | ||
| }); | ||
| // </snippet_MapEndpoints> | ||
|
|
||
| app.Run(); |
31 changes: 31 additions & 0 deletions
31
aspnetcore/tutorials/first-mongo-app/samples/10.x/BookStoreApi/Services/BooksService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // <snippet_File> | ||
| using BookStoreApi.Models; | ||
| using Microsoft.Extensions.Options; | ||
| using MongoDB.Driver; | ||
|
|
||
| namespace BookStoreApi.Services; | ||
|
|
||
| // <snippet_ctor> | ||
| 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> | ||
|
timdeschryver marked this conversation as resolved.
|
||
|
|
||
| public async Task<List<Book>> GetAsync() => | ||
| await _booksCollection.Find(_ => true).ToListAsync(); | ||
|
|
||
| public async Task<Book?> GetAsync(string id) => | ||
| await _booksCollection.Find(x => x.Id == id).FirstOrDefaultAsync(); | ||
|
|
||
| public async Task CreateAsync(Book newBook) => | ||
| await _booksCollection.InsertOneAsync(newBook); | ||
|
|
||
| public async Task UpdateAsync(string id, Book updatedBook) => | ||
| await _booksCollection.ReplaceOneAsync(x => x.Id == id, updatedBook); | ||
|
|
||
| public async Task RemoveAsync(string id) => | ||
| await _booksCollection.DeleteOneAsync(x => x.Id == id); | ||
| } | ||
| // </snippet_File> | ||
8 changes: 8 additions & 0 deletions
8
aspnetcore/tutorials/first-mongo-app/samples/10.x/BookStoreApi/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
aspnetcore/tutorials/first-mongo-app/samples/10.x/BookStoreApi/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "BookStoreDatabase": { | ||
| "ConnectionString": "mongodb://localhost:27017", | ||
| "DatabaseName": "BookStore", | ||
| "BooksCollectionName": "Books" | ||
| }, | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
20 changes: 20 additions & 0 deletions
20
aspnetcore/tutorials/first-mongo-app/samples_snapshot/10.x/Book.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using MongoDB.Bson; | ||
| using MongoDB.Bson.Serialization.Attributes; | ||
|
|
||
| namespace BookStoreApi.Models; | ||
|
|
||
| public class Book | ||
| { | ||
| [BsonId] | ||
| [BsonRepresentation(BsonType.ObjectId)] | ||
| public string? Id { get; set; } | ||
|
|
||
| [BsonElement("Name")] | ||
| public string BookName { get; set; } = null!; | ||
|
|
||
| public decimal Price { get; set; } | ||
|
|
||
| public string Category { get; set; } = null!; | ||
|
|
||
| public string Author { get; set; } = null!; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.