From 34a9a2060dca61bd8e4f6978caea9de06613605d Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 19 Sep 2023 07:13:56 +0800 Subject: [PATCH 1/8] Update target-aspnetcore.md (#30388) --- aspnetcore/fundamentals/target-aspnetcore.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/target-aspnetcore.md b/aspnetcore/fundamentals/target-aspnetcore.md index e41b2be8c64b..694048b1328f 100644 --- a/aspnetcore/fundamentals/target-aspnetcore.md +++ b/aspnetcore/fundamentals/target-aspnetcore.md @@ -268,7 +268,7 @@ For example, to add the web API client: - netcoreapp3.1 + net6.0 From e1a4f8599045ab7ab0d0856643b275f9b62d8e58 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 19 Sep 2023 07:59:01 +0800 Subject: [PATCH 2/8] Add documentation about hosting gRPC in non-ASP.NET Core projects (#30390) Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --- aspnetcore/grpc/aspnetcore.md | 23 +++++++++++++++++++- aspnetcore/grpc/aspnetcore/Server-web.csproj | 8 +++++++ aspnetcore/grpc/aspnetcore/Server.csproj | 10 +++++++++ aspnetcore/grpc/interprocess.md | 11 +--------- 4 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 aspnetcore/grpc/aspnetcore/Server-web.csproj create mode 100644 aspnetcore/grpc/aspnetcore/Server.csproj diff --git a/aspnetcore/grpc/aspnetcore.md b/aspnetcore/grpc/aspnetcore.md index 6ea06064ad0e..235850707409 100644 --- a/aspnetcore/grpc/aspnetcore.md +++ b/aspnetcore/grpc/aspnetcore.md @@ -246,6 +246,28 @@ For more information on enabling HTTP/2 and TLS with Kestrel, see [Kestrel endpo :::moniker-end +## Host gRPC in non-ASP.NET Core projects + +An ASP.NET Core gRPC server is typically created from the gRPC template. The project file created by the template uses `Microsoft.NET.SDK.Web` as the SDK: + +[!code-xml[](~/grpc/aspnetcore/Server-web.csproj?highlight=1)] + +The `Microsoft.NET.SDK.Web` SDK value automatically adds a reference to the ASP.NET Core framework. The reference allows the app to use ASP.NET Core types required to host a server. + +You can add a gRPC server to non-ASP.NET Core projects with the following project file settings: + +[!code-xml[](~/grpc/aspnetcore/Server.csproj?highlight=1,7)] + +The preceding project file: + +* Adds a framework reference to `Microsoft.AspNetCore.App`. + * The framework reference allows non-ASP.NET Core apps, such as Windows Services, WPF apps, or WinForms apps to use ASP.NET Core APIs. + * The app can now use ASP.NET Core APIs to start an ASP.NET Core server. +* Adds gRPC requirements: + * NuGet package reference to [`Grpc.AspNetCore`](https://www.nuget.org/packages/Grpc.AspNetCore). + * `.proto` file. + +For more information about using the `Microsoft.AspNetCore.App` framework reference, see [Use the ASP.NET Core shared framework](xref:fundamentals/target-aspnetcore#use-the-aspnet-core-shared-framework). ## Integration with ASP.NET Core APIs gRPC services have full access to the ASP.NET Core features such as [Dependency Injection](xref:fundamentals/dependency-injection) (DI) and [Logging](xref:fundamentals/logging/index). For example, the service implementation can resolve a logger service from the DI container via the constructor: @@ -271,7 +293,6 @@ The gRPC API provides access to some HTTP/2 message data, such as the method, ho [!code-csharp[](~/grpc/aspnetcore/sample/GrcpService/GreeterService2.cs?highlight=6-7&name=snippet)] - ## Additional resources * diff --git a/aspnetcore/grpc/aspnetcore/Server-web.csproj b/aspnetcore/grpc/aspnetcore/Server-web.csproj new file mode 100644 index 000000000000..43ec5a08fcdd --- /dev/null +++ b/aspnetcore/grpc/aspnetcore/Server-web.csproj @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/aspnetcore/grpc/aspnetcore/Server.csproj b/aspnetcore/grpc/aspnetcore/Server.csproj new file mode 100644 index 000000000000..183e67322c12 --- /dev/null +++ b/aspnetcore/grpc/aspnetcore/Server.csproj @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/aspnetcore/grpc/interprocess.md b/aspnetcore/grpc/interprocess.md index 91308df934ca..af686082696d 100644 --- a/aspnetcore/grpc/interprocess.md +++ b/aspnetcore/grpc/interprocess.md @@ -25,16 +25,7 @@ An ASP.NET Core gRPC server is usually created from the gRPC template. The proje The `Microsoft.NET.SDK.Web` SDK value automatically adds a reference to the ASP.NET Core framework. The reference allows the app to use ASP.NET Core types required to host a server. -It's also possible to add a server to existing non-ASP.NET Core projects. Add the `Microsoft.AspNetCore.App` framework to the project file: - -[!code-xml[](~/grpc/interprocess/Server.csproj?highlight=4)] - -The preceding project file: - -* Adds a framework reference to `Microsoft.AspNetCore.App`. The framework reference allows non-ASP.NET Core apps, such as Windows Services, WPF apps, or WinForms apps to use ASP.NET Core APIs. The app can now use ASP.NET Core APIs to start an ASP.NET Core server. -* Adds gRPC requirements: - * NuGet package reference to [`Grpc.AspNetCore`](https://www.nuget.org/packages/Grpc.AspNetCore). - * `.proto` file. +It's also possible to add a server to existing non-ASP.NET Core projects, such as Windows Services, WPF apps, or WinForms apps. See [Host gRPC in non-ASP.NET Core projects](xref:grpc/aspnetcore#host-grpc-in-non-aspnet-core-projects) for more information. ## Inter-process communication (IPC) transports From 4fa6aaacc5fcb056a30714f372b8ccd30e8a2a1d Mon Sep 17 00:00:00 2001 From: Wade Pickett Date: Mon, 18 Sep 2023 20:46:10 -0700 Subject: [PATCH 3/8] VS Code: Add required assets (#30363) * VS Code: Add required assets * Moved common text to two includes: vscode-trust-authors.md and vscode-add-assets-prompt.md * improve vscode-trust-authors.md * Combined new includes, added SignalR tutorials Co-authored-by: Tom Dykstra --------- Co-authored-by: Tom Dykstra --- .../vscode-trust-authors-add-assets.md | 7 ++++++ .../tutorials/first-mvc-app/start-mvc.md | 11 ++++---- .../start-mvc/includes/start-mvc5.md | 13 +++++----- .../start-mvc/includes/start-mvc6.md | 11 ++++---- .../start-mvc/includes/start-mvc7.md | 13 +++++----- aspnetcore/tutorials/first-web-api.md | 5 ++-- .../includes/first-web-api3-7.md | 15 ++++++----- aspnetcore/tutorials/grpc/grpc-start.md | 13 +++++++--- .../grpc/grpc-start/includes/grpc-start5.md | 15 ++++++++--- .../grpc/grpc-start/includes/grpc-start6.md | 13 +++++++--- .../grpc/grpc-start/includes/grpc-start7.md | 13 +++++++--- .../razor-pages/razor-pages-start.md | 25 +++++++++---------- .../includes/razor-pages-start5.md | 21 +++++++++------- .../includes/razor-pages-start6.md | 23 ++++++++--------- .../includes/razor-pages-start7.md | 23 ++++++++--------- .../tutorials/signalr-typescript-webpack.md | 2 ++ .../signalr-typescript-webpack2.1-5.md | 2 ++ .../includes/signalr-typescript-webpack6.md | 2 ++ .../includes/signalr-typescript-webpack7.md | 2 ++ aspnetcore/tutorials/signalr.md | 15 +++++------ .../tutorials/signalr/includes/signalr6.md | 2 ++ 21 files changed, 145 insertions(+), 101 deletions(-) create mode 100644 aspnetcore/includes/vscode-trust-authors-add-assets.md diff --git a/aspnetcore/includes/vscode-trust-authors-add-assets.md b/aspnetcore/includes/vscode-trust-authors-add-assets.md new file mode 100644 index 000000000000..41bed33b5ccf --- /dev/null +++ b/aspnetcore/includes/vscode-trust-authors-add-assets.md @@ -0,0 +1,7 @@ +Visual Studio Code might display a dialog box that asks: **Do you trust the authors of the files in this folder?** + +* If you trust all files in the parent folder, select **Trust the authors of all files in the parent folder**. +* Select **Yes, I trust the authors** since the project folder has files generated by .NET. +* When Visual Studio Code requests that you add assets to build and debug the project, select **Yes**. If Visual Studio Code doesn't offer to add build and debug assets, select **View** > **Command Palette** and type "`.NET`" into the search box. From the list of commands, select the `.NET: Generate Assets for Build and Debug` command. + +Visual Studio Code adds a `.vscode` folder with generated `launch.json` and `tasks.json` files. \ No newline at end of file diff --git a/aspnetcore/tutorials/first-mvc-app/start-mvc.md b/aspnetcore/tutorials/first-mvc-app/start-mvc.md index 406f2d65e89c..0f77a7f82785 100644 --- a/aspnetcore/tutorials/first-mvc-app/start-mvc.md +++ b/aspnetcore/tutorials/first-mvc-app/start-mvc.md @@ -75,19 +75,20 @@ Visual Studio uses the default project template for the created MVC project. The The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) and [Visual Studio Code help](#visual-studio-code-help). -* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). * Change to the directory (`cd`) that will contain the project. -* Run the following command: +* Run the following commands: ```dotnetcli dotnet new mvc -o MvcMovie code -r MvcMovie ``` - * If a dialog box appears with **Required assets to build and debug are missing from 'MvcMovie'. Add them?**, select **Yes** + The `dotnet new` command creates a new ASP.NET Core MVC project in the *MvcMovie* folder. - * `dotnet new mvc -o MvcMovie`: Creates a new ASP.NET Core MVC project in the *MvcMovie* folder. - * `code -r MvcMovie`: Loads the `MvcMovie.csproj` project file in Visual Studio Code. + The `code` command opens the *MvcMovie* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc5.md b/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc5.md index 0e5adbbced13..69fb523fe01b 100644 --- a/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc5.md +++ b/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc5.md @@ -54,21 +54,22 @@ Visual Studio used the default project template for the created MVC project. The # [Visual Studio Code](#tab/visual-studio-code) -The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) and [Visual Studio Code help](#visual-studio-code-help). +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). * Change to the directory (`cd`) that will contain the project. -* Run the following command: +* Run the following commands: ```dotnetcli dotnet new mvc -o MvcMovie code -r MvcMovie ``` - * If a dialog box appears with **Required assets to build and debug are missing from 'MvcMovie'. Add them?**, select **Yes** + The `dotnet new` command creates a new ASP.NET Core MVC project in the *MvcMovie* folder. - * `dotnet new mvc -o MvcMovie`: Creates a new ASP.NET Core MVC project in the *MvcMovie* folder. - * `code -r MvcMovie`: Loads the `MvcMovie.csproj` project file in Visual Studio Code. + The `code` command opens the *MvcMovie* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc6.md b/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc6.md index e787e9c835c6..6b82d2d4284d 100644 --- a/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc6.md +++ b/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc6.md @@ -58,19 +58,20 @@ Visual Studio uses the default project template for the created MVC project. The The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) and [Visual Studio Code help](#visual-studio-code-help). -* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). * Change to the directory (`cd`) that will contain the project. -* Run the following command: +* Run the following commands: ```dotnetcli dotnet new mvc -o MvcMovie code -r MvcMovie ``` - * If a dialog box appears with **Required assets to build and debug are missing from 'MvcMovie'. Add them?**, select **Yes** + The `dotnet new` command creates a new ASP.NET Core MVC project in the *MvcMovie* folder. - * `dotnet new mvc -o MvcMovie`: Creates a new ASP.NET Core MVC project in the *MvcMovie* folder. - * `code -r MvcMovie`: Loads the `MvcMovie.csproj` project file in Visual Studio Code. + The `code` command opens the *MvcMovie* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc7.md b/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc7.md index 9e9f650cfa82..d48d4ea53a81 100644 --- a/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc7.md +++ b/aspnetcore/tutorials/first-mvc-app/start-mvc/includes/start-mvc7.md @@ -59,21 +59,22 @@ Visual Studio uses the default project template for the created MVC project. The # [Visual Studio Code](#tab/visual-studio-code) -The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) and [Visual Studio Code help](#visual-studio-code-help). +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). * Change to the directory (`cd`) that will contain the project. -* Run the following command: +* Run the following commands: ```dotnetcli dotnet new mvc -o MvcMovie code -r MvcMovie ``` - * If a dialog box appears with **Required assets to build and debug are missing from 'MvcMovie'. Add them?**, select **Yes** + The `dotnet new` command creates a new ASP.NET Core MVC project in the *MvcMovie* folder. - * `dotnet new mvc -o MvcMovie`: Creates a new ASP.NET Core MVC project in the *MvcMovie* folder. - * `code -r MvcMovie`: Loads the `MvcMovie.csproj` project file in Visual Studio Code. + The `code` command opens the *MvcMovie* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/first-web-api.md b/aspnetcore/tutorials/first-web-api.md index 0899ce442437..331dc22e04ca 100644 --- a/aspnetcore/tutorials/first-web-api.md +++ b/aspnetcore/tutorials/first-web-api.md @@ -91,12 +91,13 @@ A NuGet package must be added to support the database used in this tutorial. * Create a new web API project and open it in Visual Studio Code. * Add a NuGet package that is needed for the next section. + * Open the *TodoApi* folder in the current instance of Visual Studio Code. -* When a dialog box asks if you want to add required assets to the project, select **Yes**. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) - * In Visual Studio for Mac 2022, select **File** > **New Project...**. +* In Visual Studio for Mac 2022, select **File** > **New Project...**. * In the **Choose a template for your new project** dialog: * Select **Web and Console** > **App** > **API**. diff --git a/aspnetcore/tutorials/first-web-api/includes/first-web-api3-7.md b/aspnetcore/tutorials/first-web-api/includes/first-web-api3-7.md index 85217fefa13a..7d7b69f7e344 100644 --- a/aspnetcore/tutorials/first-web-api/includes/first-web-api3-7.md +++ b/aspnetcore/tutorials/first-web-api/includes/first-web-api3-7.md @@ -64,8 +64,9 @@ The following diagram shows the design of the app. * Create a new web API project and open it in Visual Studio Code. * Add a NuGet package that is needed for the next section. + * Open the *TodoApi* folder in the current instance of Visual Studio Code. -* When a dialog box asks if you want to add required assets to the project, select **Yes**. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) @@ -593,8 +594,9 @@ The following diagram shows the design of the app. * Create a new web API project and open it in Visual Studio Code. * Add a NuGet package that is needed for the next section. + * Open the *TodoApi* folder in the current instance of Visual Studio Code. -* When a dialog box asks if you want to add required assets to the project, select **Yes**. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) @@ -1214,12 +1216,13 @@ The following diagram shows the design of the app. code -r ../TodoApi ``` -* When a dialog box asks if you want to add required assets to the project, select **Yes**. + These commands: - The preceding commands: + * Create a new web API project and open it in Visual Studio Code. + * Add a NuGet package that is needed for the next section. + * Open the *TodoApi* folder in the current instance of Visual Studio Code. - * Creates a new web API project and opens it in Visual Studio Code. - * Adds the NuGet packages which are required in the next section. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/grpc/grpc-start.md b/aspnetcore/tutorials/grpc/grpc-start.md index 8f414d7e86ee..748fe07cd61d 100644 --- a/aspnetcore/tutorials/grpc/grpc-start.md +++ b/aspnetcore/tutorials/grpc/grpc-start.md @@ -47,9 +47,9 @@ In this tutorial, you: # [Visual Studio Code](#tab/visual-studio-code) -The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). * Change to the directory (`cd`) that will contain the project. * Run the following commands: @@ -58,8 +58,11 @@ The tutorial assumes familiarity with VS Code. For more information, see [Gettin code -r GrpcGreeter ``` - * The `dotnet new` command creates a new gRPC service in the *GrpcGreeter* folder. - * The `code` command opens the *GrpcGreeter* folder in a new instance of Visual Studio Code. + The `dotnet new` command creates a new gRPC service in the *GrpcGreeter* folder. + + The `code` command opens the *GrpcGreeter* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) @@ -120,6 +123,8 @@ info: Microsoft.Hosting.Lifetime[0] code -r GrpcGreeterClient ``` +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + # [Visual Studio for Mac](#tab/visual-studio-mac) * In Visual Studio 2022 for Mac select **File** > **Add** > **Project...**. diff --git a/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start5.md b/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start5.md index 418e56422a79..96761c1aa509 100644 --- a/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start5.md +++ b/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start5.md @@ -43,9 +43,9 @@ In this tutorial, you: # [Visual Studio Code](#tab/visual-studio-code) -The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). * Change to the directory (`cd`) that will contain the project. * Run the following commands: @@ -54,8 +54,11 @@ The tutorial assumes familiarity with VS Code. For more information, see [Gettin code -r GrpcGreeter ``` - * The `dotnet new` command creates a new gRPC service in the *GrpcGreeter* folder. - * The `code` command opens the *GrpcGreeter* folder in a new instance of Visual Studio Code. + The `dotnet new` command creates a new gRPC service in the *GrpcGreeter* folder. + + The `code` command opens the *GrpcGreeter* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) @@ -115,6 +118,10 @@ info: Microsoft.Hosting.Lifetime[0] code -r GrpcGreeterClient ``` +* Visual Studio Code requests that you add assets to build and debug the project, select **Yes**. + + Visual Studio Code adds a `.vscode` folder with generated `launch.json` and `tasks.json` files. + # [Visual Studio for Mac](#tab/visual-studio-mac) Follow the instructions in [Building a complete .NET Core solution on macOS using Visual Studio for Mac](/dotnet/core/tutorials/using-on-mac-vs-full-solution) to create a console app with the name *GrpcGreeterClient*. diff --git a/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start6.md b/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start6.md index 3fe4f0b4640a..7a3dd24f642f 100644 --- a/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start6.md +++ b/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start6.md @@ -36,9 +36,9 @@ In this tutorial, you: # [Visual Studio Code](#tab/visual-studio-code) -The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). * Change to the directory (`cd`) that will contain the project. * Run the following commands: @@ -47,8 +47,11 @@ The tutorial assumes familiarity with VS Code. For more information, see [Gettin code -r GrpcGreeter ``` - * The `dotnet new` command creates a new gRPC service in the *GrpcGreeter* folder. - * The `code` command opens the *GrpcGreeter* folder in a new instance of Visual Studio Code. + The `dotnet new` command creates a new gRPC service in the *GrpcGreeter* folder. + + The `code` command opens the *GrpcGreeter* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) @@ -111,6 +114,8 @@ info: Microsoft.Hosting.Lifetime[0] code -r GrpcGreeterClient ``` +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + # [Visual Studio for Mac](#tab/visual-studio-mac) Follow the instructions in [Building a complete .NET Core solution on macOS using Visual Studio for Mac](/dotnet/core/tutorials/using-on-mac-vs-full-solution) to create a console app with the name *GrpcGreeterClient*. diff --git a/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start7.md b/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start7.md index f474b8315710..8241d50babf6 100644 --- a/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start7.md +++ b/aspnetcore/tutorials/grpc/grpc-start/includes/grpc-start7.md @@ -37,9 +37,9 @@ In this tutorial, you: # [Visual Studio Code](#tab/visual-studio-code) -The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -* Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). * Change to the directory (`cd`) that will contain the project. * Run the following commands: @@ -48,8 +48,11 @@ The tutorial assumes familiarity with VS Code. For more information, see [Gettin code -r GrpcGreeter ``` - * The `dotnet new` command creates a new gRPC service in the *GrpcGreeter* folder. - * The `code` command opens the *GrpcGreeter* folder in a new instance of Visual Studio Code. + The `dotnet new` command creates a new gRPC service in the *GrpcGreeter* folder. + + The `code` command opens the *GrpcGreeter* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) @@ -112,6 +115,8 @@ info: Microsoft.Hosting.Lifetime[0] code -r GrpcGreeterClient ``` +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + # [Visual Studio for Mac](#tab/visual-studio-mac) Follow the instructions in [Building a complete .NET Core solution on macOS using Visual Studio for Mac](/dotnet/core/tutorials/using-on-mac-vs-full-solution) to create a console app with the name *GrpcGreeterClient*. diff --git a/aspnetcore/tutorials/razor-pages/razor-pages-start.md b/aspnetcore/tutorials/razor-pages/razor-pages-start.md index 07947df64afb..a460898b66e7 100644 --- a/aspnetcore/tutorials/razor-pages/razor-pages-start.md +++ b/aspnetcore/tutorials/razor-pages/razor-pages-start.md @@ -4,7 +4,7 @@ author: wadepickett description: This is the first tutorial of a series that teaches the basics of building an ASP.NET Core Razor Pages web app. ms.author: wpickett monikerRange: '>= aspnetcore-3.1' -ms.date: 08/16/2023 +ms.date: 09/12/2023 ms.custom: engagement-fy23 uid: tutorials/razor-pages/razor-pages-start --- @@ -64,23 +64,22 @@ For alternative approaches to create the project, see [Create a new project in V # [Visual Studio Code](#tab/visual-studio-code) -1. Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -1. Change to the directory (`cd`) that will contain the project. -1. Run the following commands: +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Change to the directory (`cd`) that will contain the project. +* Run the following commands: - ```dotnetcli - dotnet new webapp -o RazorPagesMovie - code -r RazorPagesMovie - ``` + ```dotnetcli + dotnet new webapp -o RazorPagesMovie + code -r RazorPagesMovie + ``` - Visual Studio Code displays a dialog box that asks **Do you trust the authors of the files in this folder**. Select: - * The checkbox **trust the authors of all files in the parent folder** - * **Yes, I trust the authors** (because dotnet generated the files). + The `dotnet new` command creates a new Razor Pages project in the *RazorPagesMovie* folder. - The `dotnet new` command creates a new Razor Pages project in the *RazorPagesMovie* folder. + The `code` command opens the *RazorPagesMovie* folder in the current instance of Visual Studio Code. - The `code` command opens the *RazorPagesMovie* folder in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start5.md b/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start5.md index 57b40bb32c62..b6dc93c1f013 100644 --- a/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start5.md +++ b/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start5.md @@ -66,19 +66,22 @@ At the end of this tutorial, you'll have a working Razor Pages web app that you' # [Visual Studio Code](#tab/visual-studio-code) -1. Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -1. Change to the directory (`cd`) which will contain the project. +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Change to the directory (`cd`) that will contain the project. +* Run the following commands: -1. Run the following commands: + ```dotnetcli + dotnet new webapp -o RazorPagesMovie + code -r RazorPagesMovie + ``` - ```dotnetcli - dotnet new webapp -o RazorPagesMovie - code -r RazorPagesMovie - ``` + The `dotnet new` command creates a new Razor Pages project in the *RazorPagesMovie* folder. - * The `dotnet new` command creates a new Razor Pages project in the *RazorPagesMovie* folder. - * The `code` command opens the *RazorPagesMovie* folder in the current instance of Visual Studio Code. + The `code` command opens the *RazorPagesMovie* project folder in the current instance of Visual Studio Code. + +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start6.md b/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start6.md index 400361c5ff92..1056696ad2cf 100644 --- a/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start6.md +++ b/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start6.md @@ -62,23 +62,22 @@ At the end of this tutorial, you'll have a working Razor Pages web app that you' # [Visual Studio Code](#tab/visual-studio-code) -1. Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -1. Change to the directory (`cd`) that will contain the project. -1. Run the following commands: +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Change to the directory (`cd`) that will contain the project. +* Run the following commands: - ```dotnetcli - dotnet new webapp -o RazorPagesMovie - code -r RazorPagesMovie - ``` + ```dotnetcli + dotnet new webapp -o RazorPagesMovie + code -r RazorPagesMovie + ``` - Visual Studio Code displays a dialog box that asks **Do you trust the authors of the files in this folder**. Select: - * The checkbox **trust the authors of all files in the parent folder** - * **Yes, I trust the authors** (because dotnet generated the files). + The `dotnet new` command creates a new Razor Pages project in the *RazorPagesMovie* folder. - The `dotnet new` command creates a new Razor Pages project in the *RazorPagesMovie* folder. + The `code` command opens the *RazorPagesMovie* project folder in the current instance of Visual Studio Code. - The `code` command opens the *RazorPagesMovie* folder in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start7.md b/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start7.md index 408c6f99a87d..c49369553a80 100644 --- a/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start7.md +++ b/aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start7.md @@ -49,23 +49,22 @@ For alternative approaches to create the project, see [Create a new project in V # [Visual Studio Code](#tab/visual-studio-code) -1. Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs). -1. Change to the directory (`cd`) that will contain the project. -1. Run the following commands: +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Change to the directory (`cd`) that will contain the project. +* Run the following commands: - ```dotnetcli - dotnet new webapp -o RazorPagesMovie - code -r RazorPagesMovie - ``` + ```dotnetcli + dotnet new webapp -o RazorPagesMovie + code -r RazorPagesMovie + ``` - Visual Studio Code displays a dialog box that asks **Do you trust the authors of the files in this folder**. Select: - * The checkbox **trust the authors of all files in the parent folder** - * **Yes, I trust the authors** (because dotnet generated the files). + The `dotnet new` command creates a new Razor Pages project in the *RazorPagesMovie* folder. - The `dotnet new` command creates a new Razor Pages project in the *RazorPagesMovie* folder. + The `code` command opens the *RazorPagesMovie* project folder in the current instance of Visual Studio Code. - The `code` command opens the *RazorPagesMovie* folder in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) diff --git a/aspnetcore/tutorials/signalr-typescript-webpack.md b/aspnetcore/tutorials/signalr-typescript-webpack.md index f8cdb75078f6..744bbc609e59 100644 --- a/aspnetcore/tutorials/signalr-typescript-webpack.md +++ b/aspnetcore/tutorials/signalr-typescript-webpack.md @@ -81,6 +81,8 @@ code -r SignalRWebpack * The `dotnet new` command creates an empty ASP.NET Core web app in a `SignalRWebpack` directory. * The `code` command opens the `SignalRWebpack` directory in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + Run the following .NET CLI command in the **Integrated Terminal**: ```dotnetcli diff --git a/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack2.1-5.md b/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack2.1-5.md index cd487b893bc3..0263150e4fb4 100644 --- a/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack2.1-5.md +++ b/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack2.1-5.md @@ -66,6 +66,8 @@ code -r SignalRWebPack * The `dotnet new` command creates an empty ASP.NET Core web app in a `SignalRWebPack` directory. * The `code` command opens the `SignalRWebPack` folder in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + Run the following .NET Core CLI command in the **Integrated Terminal**: ```dotnetcli diff --git a/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack6.md b/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack6.md index 44c5dc9fca2e..21209d03daf9 100644 --- a/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack6.md +++ b/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack6.md @@ -63,6 +63,8 @@ Visual Studio adds the NuGet package under the **Dependencies** node in **Soluti * The `dotnet new` command creates an empty ASP.NET Core web app in a `SignalRWebpack` directory. * The `code` command opens the `SignalRWebpack` directory in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + 1. Run the following .NET CLI command in the **Integrated Terminal**: ```dotnetcli diff --git a/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack7.md b/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack7.md index beb579a2da22..9bab98120d10 100644 --- a/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack7.md +++ b/aspnetcore/tutorials/signalr-typescript-webpack/includes/signalr-typescript-webpack7.md @@ -64,6 +64,8 @@ Visual Studio adds the NuGet package under the **Dependencies** node in **Soluti * The `dotnet new` command creates an empty ASP.NET Core web app in a `SignalRWebpack` directory. * The `code` command opens the `SignalRWebpack` directory in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + 1. Run the following .NET CLI command in the **Integrated Terminal**: ```dotnetcli diff --git a/aspnetcore/tutorials/signalr.md b/aspnetcore/tutorials/signalr.md index 132735504e06..b52e27040995 100644 --- a/aspnetcore/tutorials/signalr.md +++ b/aspnetcore/tutorials/signalr.md @@ -69,26 +69,23 @@ In the **Additional information** dialog, select **.NET 7.0 (Standard Term Suppo # [Visual Studio Code](#tab/visual-studio-code) -Open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +The tutorial assumes familiarity with VS Code. For more information, see [Getting started with VS Code](https://code.visualstudio.com/docs) -Change to the directory (`cd`) that will contain the project. - -Run the following commands: +* Select **New Terminal** from the **Terminal** menu to open the [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal). +* Change to the directory (`cd`) that will contain the project. +* Run the following commands: ```dotnetcli dotnet new webapp -o SignalRChat code -r SignalRChat ``` -Visual Studio Code displays a dialog box that asks **Do you trust the authors of the files in this folder**. Select: - -* The checkbox **trust the authors of all files in the parent folder** -* **Yes, I trust the authors** (because dotnet generated the files). - The `dotnet new` command creates a new Razor Pages project in the `SignalRChat` folder. The `code` command opens the `SignalRChat1 folder in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + # [Visual Studio for Mac](#tab/visual-studio-mac) Select **File** > **New Project**. diff --git a/aspnetcore/tutorials/signalr/includes/signalr6.md b/aspnetcore/tutorials/signalr/includes/signalr6.md index 4aa6b6c7c232..50e84e59ec05 100644 --- a/aspnetcore/tutorials/signalr/includes/signalr6.md +++ b/aspnetcore/tutorials/signalr/includes/signalr6.md @@ -71,6 +71,8 @@ The `dotnet new` command creates a new Razor Pages project in the `SignalRChat` The `code` command opens the `SignalRChat1 folder in the current instance of Visual Studio Code. +[!INCLUDE[](~/includes/vscode-trust-authors-add-assets.md)] + # [Visual Studio for Mac](#tab/visual-studio-mac) Select **File** > **New Solution**. From dc1cf03a614848e203b1f79a7311881bae6a87eb Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:15:21 -0400 Subject: [PATCH 4/8] Blazor with EF Core article updates 8.0 (#30405) --- .openpublishing.redirection.json | 5 ++ ...or-server-ef-core.md => blazor-ef-core.md} | 88 +++++++++++++++---- .../fundamentals/dependency-injection.md | 4 +- aspnetcore/toc.yml | 4 +- .../whats-new/dotnet-AspNetCore.Docs-mod5.md | 2 +- 5 files changed, 79 insertions(+), 24 deletions(-) rename aspnetcore/blazor/{blazor-server-ef-core.md => blazor-ef-core.md} (75%) diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index 53245c6fe6e4..9206b88cee83 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -1252,6 +1252,11 @@ "source_path": "aspnetcore/blazor/tutorials/signalr-blazor-preview.md", "redirect_url": "/aspnet/core/blazor/tutorials/signalr-blazor", "redirect_document_id": false + }, + { + "source_path": "aspnetcore/blazor/blazor-server-ef-core.md", + "redirect_url": "/aspnet/core/blazor/blazor-ef-core", + "redirect_document_id": false } ] } diff --git a/aspnetcore/blazor/blazor-server-ef-core.md b/aspnetcore/blazor/blazor-ef-core.md similarity index 75% rename from aspnetcore/blazor/blazor-server-ef-core.md rename to aspnetcore/blazor/blazor-ef-core.md index 96e9b70799b8..e001cb34f194 100644 --- a/aspnetcore/blazor/blazor-server-ef-core.md +++ b/aspnetcore/blazor/blazor-ef-core.md @@ -1,33 +1,39 @@ --- -title: ASP.NET Core Blazor Server with Entity Framework Core (EF Core) +title: ASP.NET Core Blazor with Entity Framework Core (EF Core) author: guardrex -description: Learn how to use Entity Framework Core (EF Core) in Blazor Server apps. +description: Learn how to use Entity Framework Core (EF Core) in Blazor apps. monikerRange: '>= aspnetcore-3.1' ms.author: jeliknes ms.custom: mvc ms.date: 03/27/2023 -uid: blazor/blazor-server-ef-core +uid: blazor/blazor-ef-core --- -# ASP.NET Core Blazor Server with Entity Framework Core (EF Core) +# ASP.NET Core Blazor with Entity Framework Core (EF Core) [!INCLUDE[](~/includes/not-latest-version.md)] -This article explains how to use [Entity Framework Core (EF Core)](/ef/core/) in Blazor Server apps. +This article explains how to use [Entity Framework Core (EF Core)](/ef/core/) in server-side Blazor apps. -Blazor Server is a stateful app framework. The app maintains an ongoing connection to the server, and the user's state is held in the server's memory in a *circuit*. One example of user state is data held in [dependency injection (DI)](xref:fundamentals/dependency-injection) service instances that are scoped to the circuit. The unique application model that Blazor Server provides requires a special approach to use Entity Framework Core. +Server-side Blazor is a stateful app framework. The app maintains an ongoing connection to the server, and the user's state is held in the server's memory in a *circuit*. One example of user state is data held in [dependency injection (DI)](xref:fundamentals/dependency-injection) service instances that are scoped to the circuit. The unique application model that Blazor provides requires a special approach to use Entity Framework Core. > [!NOTE] -> This article addresses EF Core in Blazor Server apps. Blazor WebAssembly apps run in a WebAssembly sandbox that prevents most direct database connections. Running EF Core in Blazor WebAssembly is beyond the scope of this article. +> This article addresses EF Core in server-side Blazor apps. Blazor WebAssembly apps run in a WebAssembly sandbox that prevents most direct database connections. Running EF Core in Blazor WebAssembly is beyond the scope of this article. ## Sample app -The sample app was built as a reference for Blazor Server apps that use EF Core. The sample app includes a grid with sorting and filtering, delete, add, and update operations. The sample demonstrates use of EF Core to handle optimistic concurrency. +The sample app was built as a reference for server-side Blazor apps that use EF Core. The sample app includes a grid with sorting and filtering, delete, add, and update operations. The sample demonstrates use of EF Core to handle optimistic concurrency. [View or download sample code](https://github.com/dotnet/blazor-samples) ([how to download](xref:index#how-to-download-a-sample)) The sample uses a local [SQLite](https://www.sqlite.org/index.html) database so that it can be used on any platform. The sample also configures database logging to show the SQL queries that are generated. This is configured in `appsettings.Development.json`: -:::moniker range=">= aspnetcore-7.0" +:::moniker range=">= aspnetcore-8.0" + +:::code language="json" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/appsettings.Development.json" highlight="8"::: + +:::moniker-end + +:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0" :::code language="json" source="~/../blazor-samples/7.0/BlazorServerEFCoreSample/appsettings.Development.json" highlight="8"::: @@ -58,13 +64,13 @@ The grid, add, and view components use the "context-per-operation" pattern, wher ## Database access -EF Core relies on a as the means to [configure database access](/ef/core/miscellaneous/configuring-dbcontext) and act as a [*unit of work*](https://martinfowler.com/eaaCatalog/unitOfWork.html). EF Core provides the extension for ASP.NET Core apps that registers the context as a *scoped* service by default. In Blazor Server apps, scoped service registrations can be problematic because the instance is shared across components within the user's circuit. isn't thread safe and isn't designed for concurrent use. The existing lifetimes are inappropriate for these reasons: +EF Core relies on a as the means to [configure database access](/ef/core/miscellaneous/configuring-dbcontext) and act as a [*unit of work*](https://martinfowler.com/eaaCatalog/unitOfWork.html). EF Core provides the extension for ASP.NET Core apps that registers the context as a *scoped* service by default. In server-side Blazor apps, scoped service registrations can be problematic because the instance is shared across components within the user's circuit. isn't thread safe and isn't designed for concurrent use. The existing lifetimes are inappropriate for these reasons: * **Singleton** shares state across all users of the app and leads to inappropriate concurrent use. * **Scoped** (the default) poses a similar issue between components for the same user. * **Transient** results in a new instance per request; but as components can be long-lived, this results in a longer-lived context than may be intended. -The following recommendations are designed to provide a consistent approach to using EF Core in Blazor Server apps. +The following recommendations are designed to provide a consistent approach to using EF Core in server-side Blazor apps. * By default, consider using one context per operation. The context is designed for fast, low overhead instantiation: @@ -124,7 +130,13 @@ In the preceding factory: The following example configures [SQLite](https://www.sqlite.org/index.html) and enables data logging. The code uses an extension method (`AddDbContextFactory`) to configure the database factory for DI and provide default options: -:::moniker range=">= aspnetcore-7.0" +:::moniker range=">= aspnetcore-8.0" + +:::code language="csharp" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/Program.cs" id="snippet1"::: + +:::moniker-end + +:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0" :::code language="csharp" source="~/../blazor-samples/7.0/BlazorServerEFCoreSample/Program.cs" id="snippet1"::: @@ -150,7 +162,7 @@ The following example configures [SQLite](https://www.sqlite.org/index.html) and The factory is injected into components and used to create new `DbContext` instances. -In `Pages/Index.razor` of the [sample app](https://github.com/dotnet/blazor-samples/blob/main/7.0/BlazorServerEFCoreSample/Pages/Index.razor), `IDbContextFactory` is injected into the component: +In the home page of the sample app, `IDbContextFactory` is injected into the component: ```razor @inject IDbContextFactory DbFactory @@ -158,7 +170,13 @@ In `Pages/Index.razor` of the [sample app](https://github.com/dotnet/blazor-samp A `DbContext` is created using the factory (`DbFactory`) to delete a contact in the `DeleteContactAsync` method: -:::moniker range=">= aspnetcore-7.0" +:::moniker range=">= aspnetcore-8.0" + +:::code language="csharp" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/Components/Pages/Home.razor" id="snippet1"::: + +:::moniker-end + +:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0" :::code language="csharp" source="~/../blazor-samples/7.0/BlazorServerEFCoreSample/Pages/Index.razor" id="snippet1"::: @@ -182,13 +200,35 @@ A `DbContext` is created using the factory (`DbFactory`) to delete a contact in :::moniker-end +:::moniker range=">= aspnetcore-8.0" + +> [!NOTE] +> `Filters` is an injected `IContactFilters`, and `Wrapper` is a [component reference](xref:blazor/components/index#capture-references-to-components) to the `GridWrapper` component. See the `Home` component (`Components/Pages/Home.razor`) in the sample app. + +:::moniker-end + +:::moniker range="< aspnetcore-8.0" + > [!NOTE] -> `Filters` is an injected `IContactFilters`, and `Wrapper` is a [component reference](xref:blazor/components/index#capture-references-to-components) to the `GridWrapper` component. See the `Index` component (`Pages/Index.razor`) in the [sample app](https://github.com/dotnet/blazor-samples/blob/main/6.0/BlazorServerEFCoreSample/Pages/Index.razor). +> `Filters` is an injected `IContactFilters`, and `Wrapper` is a [component reference](xref:blazor/components/index#capture-references-to-components) to the `GridWrapper` component. See the `Index` component (`Pages/Index.razor`) in the sample app. + +:::moniker-end ## Scope to the component lifetime You may wish to create a that exists for the lifetime of a component. This allows you to use it as a [unit of work](https://martinfowler.com/eaaCatalog/unitOfWork.html) and take advantage of built-in features, such as change tracking and concurrency resolution. -You can use the factory to create a context and track it for the lifetime of the component. First, implement and inject the factory as shown in `Pages/EditContact.razor`: + +:::moniker range=">= aspnetcore-8.0" + +You can use the factory to create a context and track it for the lifetime of the component. First, implement and inject the factory as shown in the `EditContact` component (`Components/Pages/EditContact.razor`): + +:::moniker-end + +:::moniker range="< aspnetcore-8.0" + +You can use the factory to create a context and track it for the lifetime of the component. First, implement and inject the factory as shown in the `EditContact` component (`Pages/EditContact.razor`): + +:::moniker-end ```razor @implements IDisposable @@ -197,7 +237,13 @@ You can use the factory to create a context and track it for the lifetime of the The sample app ensures the context is disposed when the component is disposed: -:::moniker range=">= aspnetcore-7.0" +:::moniker range=">= aspnetcore-8.0" + +:::code language="csharp" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/Components/Pages/EditContact.razor" id="snippet1"::: + +:::moniker-end + +:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0" :::code language="csharp" source="~/../blazor-samples/7.0/BlazorServerEFCoreSample/Pages/EditContact.razor" id="snippet1"::: @@ -223,7 +269,13 @@ The sample app ensures the context is disposed when the component is disposed: Finally, [`OnInitializedAsync`](xref:blazor/components/lifecycle) is overridden to create a new context. In the sample app, [`OnInitializedAsync`](xref:blazor/components/lifecycle) loads the contact in the same method: -:::moniker range=">= aspnetcore-7.0" +:::moniker range=">= aspnetcore-8.0" + +:::code language="csharp" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/Components/Pages/EditContact.razor" id="snippet2"::: + +:::moniker-end + +:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0" :::code language="csharp" source="~/../blazor-samples/7.0/BlazorServerEFCoreSample/Pages/EditContact.razor" id="snippet2"::: diff --git a/aspnetcore/blazor/fundamentals/dependency-injection.md b/aspnetcore/blazor/fundamentals/dependency-injection.md index 597dba6034c7..de0a881e6233 100644 --- a/aspnetcore/blazor/fundamentals/dependency-injection.md +++ b/aspnetcore/blazor/fundamentals/dependency-injection.md @@ -405,9 +405,7 @@ In spite of the scoped service registration in the `Program` file and the longev ## Use of an Entity Framework Core (EF Core) DbContext from DI - - -For more information, see . +For more information, see . ## Detect client-side transient disposables diff --git a/aspnetcore/toc.yml b/aspnetcore/toc.yml index 1436e84a4b39..888368ca047a 100644 --- a/aspnetcore/toc.yml +++ b/aspnetcore/toc.yml @@ -583,8 +583,8 @@ items: uid: blazor/host-and-deploy/webassembly-deployment-layout - name: Multiple hosted WebAssembly apps uid: blazor/host-and-deploy/multiple-hosted-webassembly - - name: Blazor Server and EF Core - uid: blazor/blazor-server-ef-core + - name: Blazor with EF Core + uid: blazor/blazor-ef-core - name: Advanced scenarios uid: blazor/advanced-scenarios - name: Client-side development diff --git a/aspnetcore/whats-new/dotnet-AspNetCore.Docs-mod5.md b/aspnetcore/whats-new/dotnet-AspNetCore.Docs-mod5.md index da43c609f777..d3c787e389eb 100644 --- a/aspnetcore/whats-new/dotnet-AspNetCore.Docs-mod5.md +++ b/aspnetcore/whats-new/dotnet-AspNetCore.Docs-mod5.md @@ -29,7 +29,7 @@ Welcome to what's new in the ASP.NET Core docs for May 2023. This article lists - Components overview versioning - - Expand lead-in coverage on app base path - - Blazor SignalR fundamentals article versioning -- - Blazor Server EF Core article versioning +- - Blazor Server EF Core article versioning - - Blazor article versioning - - Blazor article versioning - - Subpath scenario for multiple hosted WASM apps From 549a4f32c9cd1efe0d2d8566353cc424c21277e0 Mon Sep 17 00:00:00 2001 From: dsdante <4814448+dsdante@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:46:04 +0300 Subject: [PATCH 5/8] routing.md: fixed lazy matching definition (#30409) * routing.md: fixed lazy matching definition * Update aspnetcore/fundamentals/routing.md * Update routing.md * Update aspnetcore/fundamentals/routing.md --------- Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --- aspnetcore/fundamentals/routing.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/routing.md b/aspnetcore/fundamentals/routing.md index 54f476c4c6e4..07cba4d9cd89 100644 --- a/aspnetcore/fundamentals/routing.md +++ b/aspnetcore/fundamentals/routing.md @@ -3,6 +3,7 @@ title: Routing in ASP.NET Core author: rick-anderson description: Discover how ASP.NET Core routing is responsible for matching HTTP requests and dispatching to executable endpoints. monikerRange: '>= aspnetcore-3.1' +content_well_notification: AI-contribution ms.author: riande ms.custom: mvc ms.date: 6/14/2023 @@ -485,7 +486,7 @@ Regular expressions provide much more control over their matching behavior. -Greedy matching, also known as [lazy matching](https://wikipedia.org/wiki/Regular_expression#Lazy_matching), matches the largest possible string. Non-greedy matches the smallest possible string. +Greedy matching, also known as *maximal matching* attempts to find the longest possible match in the input text that satisfies the [regex](/dotnet/standard/base-types/regular-expressions) pattern. Non-greedy matching, also known as *lazy matching*, seeks the shortest possible match in the input text that satisfies the regex pattern. [!INCLUDE[](~/includes/routeSlash.md)] From ce7e798585500fc08d44e3af71a5e26b8631ec7e Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:19:02 -1000 Subject: [PATCH 6/8] Fix cors (#30411) * Fix cors * Fix cors --- aspnetcore/fundamentals/minimal-apis/security.md | 5 +++-- .../security/7.0-samples/MinApiAuth/MinApiAuth/Program.cs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/aspnetcore/fundamentals/minimal-apis/security.md b/aspnetcore/fundamentals/minimal-apis/security.md index 7f8d350c2403..5f09beade965 100644 --- a/aspnetcore/fundamentals/minimal-apis/security.md +++ b/aspnetcore/fundamentals/minimal-apis/security.md @@ -3,8 +3,9 @@ title: Authentication and authorization in minimal APIs author: captainsafia description: Learn how to configure authentication and authorization in minimal API apps ms.author: safia +content_well_notification: AI-contribution monikerRange: '>= aspnetcore-7.0' -ms.date: 10/17/2022 +ms.date: 9/17/2023 uid: fundamentals/minimal-apis/security --- @@ -41,7 +42,7 @@ By default, the [`WebApplication`](/dotnet/api/microsoft.aspnetcore.builder.weba In some cases, such as controlling middleware order, it's necessary to explicitly register authentication and authorization. In the following sample, the authentication middleware runs _after_ the CORS middleware has run. For more information on middlewares and this automatic behavior, see [Middleware in Minimal API apps](/aspnet/core/fundamentals/minimal-apis/middleware). -:::code language="csharp" source="~/fundamentals/minimal-apis/security/7.0-samples/MinApiAuth/MinApiAuth/Program.cs" id="snippet_after" highlight="8-10"::: +:::code language="csharp" source="~/fundamentals/minimal-apis/security/7.0-samples/MinApiAuth/MinApiAuth/Program.cs" id="snippet_after" highlight="9-11"::: ### Configuring authentication strategy diff --git a/aspnetcore/fundamentals/minimal-apis/security/7.0-samples/MinApiAuth/MinApiAuth/Program.cs b/aspnetcore/fundamentals/minimal-apis/security/7.0-samples/MinApiAuth/MinApiAuth/Program.cs index d705d385fb3c..400f07923c3c 100644 --- a/aspnetcore/fundamentals/minimal-apis/security/7.0-samples/MinApiAuth/MinApiAuth/Program.cs +++ b/aspnetcore/fundamentals/minimal-apis/security/7.0-samples/MinApiAuth/MinApiAuth/Program.cs @@ -1,4 +1,4 @@ -#define GREET // FIRST JWT1 JWT2 AFTER LOCAL GREET +#define AFTER // FIRST JWT1 JWT2 AFTER LOCAL GREET #if NEVER #elif FIRST // @@ -33,6 +33,7 @@ // var builder = WebApplication.CreateBuilder(args); +builder.Services.AddCors(); builder.Services.AddAuthentication().AddJwtBearer(); builder.Services.AddAuthorization(); From 07716d9553149e8cf8a24788e14d32f5ecc396be Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:45:48 -1000 Subject: [PATCH 7/8] Update app-secrets.md (#30412) * Update app-secrets.md * Update app-secrets.md --- aspnetcore/security/app-secrets.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aspnetcore/security/app-secrets.md b/aspnetcore/security/app-secrets.md index e3703f16cc13..9a8215ab0496 100644 --- a/aspnetcore/security/app-secrets.md +++ b/aspnetcore/security/app-secrets.md @@ -281,7 +281,8 @@ See [this GitHub issue](https://github.com/dotnet/AspNetCore.Docs/issues/27611). ## Additional resources -* See [this issue](https://github.com/dotnet/AspNetCore.Docs/issues/16328) for information on accessing user secrets from IIS. + +* See [this issue](https://github.com/dotnet/AspNetCore.Docs/issues/30378) and [this issue](https://github.com/dotnet/AspNetCore.Docs/issues/16328) for information on accessing user secrets from IIS. * * @@ -558,7 +559,7 @@ See [this GitHub issue](https://github.com/dotnet/AspNetCore.Docs/issues/27611). ## Additional resources -* See [this issue](https://github.com/dotnet/AspNetCore.Docs/issues/16328) for information on accessing user secrets from IIS. +* See [this issue](https://github.com/dotnet/AspNetCore.Docs/issues/30378) and [this issue](https://github.com/dotnet/AspNetCore.Docs/issues/16328) for information on accessing user secrets from IIS. * * From 7eb5a6b9ee41b719adb170fe399bc1a2d97c4f91 Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Tue, 19 Sep 2023 14:32:12 -1000 Subject: [PATCH 8/8] antiforger is available in .NET 8 /1 (#30413) * antiforger is available in .NET 8 /1 * antiforger is available in .NET 8 /1 --- .../fundamentals/minimal-apis/includes/parameter-binding7.md | 2 +- .../fundamentals/minimal-apis/includes/parameter-binding8.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aspnetcore/fundamentals/minimal-apis/includes/parameter-binding7.md b/aspnetcore/fundamentals/minimal-apis/includes/parameter-binding7.md index 65cbd1a23378..f81e15396497 100644 --- a/aspnetcore/fundamentals/minimal-apis/includes/parameter-binding7.md +++ b/aspnetcore/fundamentals/minimal-apis/includes/parameter-binding7.md @@ -168,7 +168,7 @@ The following code uses and diff --git a/aspnetcore/fundamentals/minimal-apis/includes/parameter-binding8.md b/aspnetcore/fundamentals/minimal-apis/includes/parameter-binding8.md index bafec49fb439..515096b28437 100644 --- a/aspnetcore/fundamentals/minimal-apis/includes/parameter-binding8.md +++ b/aspnetcore/fundamentals/minimal-apis/includes/parameter-binding8.md @@ -181,7 +181,7 @@ The following code uses and #### Binding to forms with IFormCollection, IFormFile, and IFormFileCollection