From 3ff41ac907ba59acbd5200346e1f41f87351e054 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Thu, 7 Oct 2021 07:47:00 -0500 Subject: [PATCH 1/5] Blazor minimal API updates --- aspnetcore/blazor/call-web-api.md | 24 +-- .../blazor/components/control-head-content.md | 2 +- aspnetcore/blazor/components/index.md | 14 +- .../prerendering-and-integration.md | 8 +- aspnetcore/blazor/debug.md | 24 +-- aspnetcore/blazor/file-uploads.md | 4 +- aspnetcore/blazor/forms-validation.md | 10 +- .../blazor/fundamentals/configuration.md | 48 +++--- .../fundamentals/dependency-injection.md | 159 +++++++----------- .../blazor/fundamentals/environments.md | 12 +- .../blazor/fundamentals/handle-errors.md | 12 +- aspnetcore/blazor/fundamentals/logging.md | 6 +- aspnetcore/blazor/fundamentals/routing.md | 18 +- aspnetcore/blazor/fundamentals/signalr.md | 26 ++- .../blazor/fundamentals/static-files.md | 6 +- .../blazor/globalization-localization.md | 81 +++++---- aspnetcore/blazor/host-and-deploy/index.md | 8 +- aspnetcore/blazor/host-and-deploy/server.md | 4 +- .../blazor/host-and-deploy/webassembly.md | 27 ++- .../blazor/includes/js-interop/size-limits.md | 9 +- aspnetcore/blazor/includes/state-container.md | 10 +- .../call-javascript-from-dotnet.md | 4 +- aspnetcore/blazor/project-structure.md | 8 +- .../BlazorSample_Server/routing/Program.cs | 4 + .../BlazorSample_Server/routing/Startup.cs | 15 -- .../security/content-security-policy.md | 6 +- .../blazor/security/includes/azure-scope.md | 4 +- .../blazor/security/includes/troubleshoot.md | 4 +- .../includes/usermanager-signinmanager.md | 13 +- aspnetcore/blazor/security/index.md | 10 +- .../security/server/additional-scenarios.md | 10 +- .../security/server/threat-mitigation.md | 6 +- .../webassembly/additional-scenarios.md | 124 +++++++------- ...azure-active-directory-groups-and-roles.md | 24 +-- .../blazor/security/webassembly/graph-api.md | 32 ++-- .../hosted-with-azure-active-directory-b2c.md | 12 +- .../hosted-with-azure-active-directory.md | 6 +- .../hosted-with-identity-server.md | 28 +-- .../webassembly-lazy-load-assemblies.md | 6 +- 39 files changed, 389 insertions(+), 439 deletions(-) create mode 100644 aspnetcore/blazor/samples/6.0/BlazorSample_Server/routing/Program.cs delete mode 100644 aspnetcore/blazor/samples/6.0/BlazorSample_Server/routing/Startup.cs diff --git a/aspnetcore/blazor/call-web-api.md b/aspnetcore/blazor/call-web-api.md index db0a7cdb3763..8a7f88cd05b4 100644 --- a/aspnetcore/blazor/call-web-api.md +++ b/aspnetcore/blazor/call-web-api.md @@ -45,7 +45,7 @@ Reference the [`System.Net.Http.Json`](https://www.nuget.org/packages/System.Net ## Add the `HttpClient` service -In `Program.Main`, add an service if it isn't already present from a Blazor project template used to create the app: +In `Program.cs`, add an service if it isn't already present from a Blazor project template used to create the app: ```csharp builder.Services.AddScoped(sp => @@ -210,7 +210,7 @@ Reference the [`Microsoft.Extensions.Http`](https://www.nuget.org/packages/Micro In the preceding example, the `{VERSION}` placeholder is the version of the package. -In `Program.Main` of the `Program.cs` file: +In `Program.cs`: ```csharp builder.Services.AddHttpClient("WebAPI", client => @@ -303,7 +303,7 @@ public class WeatherForecastHttpClient } ``` -In `Program.Main` of the `Program.cs` file: +In `Program.cs`: ```csharp builder.Services.AddHttpClient(client => @@ -389,7 +389,7 @@ For more information on Fetch API options, see [MDN web docs: WindowOrWorkerGlob The following example calls a web API. The example requires a running web API based on the sample app described by the article. This example makes requests to the web API at `https://localhost:10000/api/TodoItems`. If a different web API address is used, update the `ServiceEndpoint` constant value in the component's `@code` block. -The following example makes a [cross-origin resource sharing (CORS)](xref:security/cors) request from `http://localhost:5000` or `https://localhost:5001` to the web API. Add the following CORS middleware configuration to the web API's service's `Startup.Configure` method: +The following example makes a [cross-origin resource sharing (CORS)](xref:security/cors) request from `http://localhost:5000` or `https://localhost:5001` to the web API. Add the following CORS middleware configuration to the web API's service's `Program.cs` file: ```csharp app.UseCors(policy => @@ -484,10 +484,10 @@ For more information, see . A Blazor Server app doesn't include an service by default. Provide an to the app using the [`HttpClient` factory infrastructure](xref:fundamentals/http-requests). -In `Startup.`ConfigureServices` of `Startup.cs`: +In `Program.cs`: ```csharp -services.AddHttpClient(); +builder.Services.AddHttpClient(); ``` The following Blazor Server Razor component makes a request to a web API for GitHub branches similar to the *Basic Usage* example in the article. @@ -641,7 +641,7 @@ Reference the [`System.Net.Http.Json`](https://www.nuget.org/packages/System.Net ## Add the `HttpClient` service -In `Program.Main`, add an service if it isn't already present from a Blazor project template used to create the app: +In `Program.cs`, add an service if it isn't already present from a Blazor project template used to create the app: ```csharp builder.Services.AddScoped(sp => @@ -806,7 +806,7 @@ Reference the [`Microsoft.Extensions.Http`](https://www.nuget.org/packages/Micro In the preceding example, the `{VERSION}` placeholder is the version of the package. -In `Program.Main` of the `Program.cs` file: +In `Program.cs`: ```csharp builder.Services.AddHttpClient("WebAPI", client => @@ -899,7 +899,7 @@ public class WeatherForecastHttpClient } ``` -In `Program.Main` of the `Program.cs` file: +In `Program.cs`: ```csharp builder.Services.AddHttpClient(client => @@ -1239,7 +1239,7 @@ Reference the [`System.Net.Http.Json`](https://www.nuget.org/packages/System.Net ## Add the `HttpClient` service -In `Program.Main`, add an service if it isn't already present from a Blazor project template used to create the app: +In `Program.cs`, add an service if it isn't already present from a Blazor project template used to create the app: ```csharp builder.Services.AddScoped(sp => @@ -1404,7 +1404,7 @@ Reference the [`Microsoft.Extensions.Http`](https://www.nuget.org/packages/Micro In the preceding example, the `{VERSION}` placeholder is the version of the package. -In `Program.Main` of the `Program.cs` file: +In `Program.cs`: ```csharp builder.Services.AddHttpClient("WebAPI", client => @@ -1497,7 +1497,7 @@ public class WeatherForecastHttpClient } ``` -In `Program.Main` of the `Program.cs` file: +In `Program.cs`: ```csharp builder.Services.AddHttpClient(client => diff --git a/aspnetcore/blazor/components/control-head-content.md b/aspnetcore/blazor/components/control-head-content.md index e24956437f3a..4a563f9e6c20 100644 --- a/aspnetcore/blazor/components/control-head-content.md +++ b/aspnetcore/blazor/components/control-head-content.md @@ -48,7 +48,7 @@ Specify the page's title with the `PageTitle` component. Specify `` elemen The `HeadOutlet` component renders content provided by `HeadContent` components. -In an app created from the Blazor WebAssembly project template, the `HeadOutlet` component is added to the collection of the in `Program.Main`: +In an app created from the Blazor WebAssembly project template, the `HeadOutlet` component is added to the collection of the in `Program.cs`: ```csharp builder.RootComponents.Add("head::after"); diff --git a/aspnetcore/blazor/components/index.md b/aspnetcore/blazor/components/index.md index efc630cc67f5..a01742bcb3b7 100644 --- a/aspnetcore/blazor/components/index.md +++ b/aspnetcore/blazor/components/index.md @@ -665,18 +665,18 @@ In the event a component must be updated based on an external event, such as a t Register the services: -* In a Blazor WebAssembly app, register the services as singletons in `Program.Main`: +* In a Blazor WebAssembly app, register the services as singletons in `Program.cs`: ```csharp builder.Services.AddSingleton(); builder.Services.AddSingleton(); ``` -* In a Blazor Server app, register the services as scoped in `Startup.ConfigureServices`: +* In a Blazor Server app, register the services as scoped in `Program.cs`: ```csharp - services.AddScoped(); - services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); ``` Use the `NotifierService` to update a component. @@ -1057,7 +1057,7 @@ await Blazor.rootComponents.add(containerElement, 'counter', { incrementAmount: ## Blazor custom elements -Experimental support is available for building custom elements using the the [`Microsoft.AspNetCore.Components.CustomElements` NuGet package](https://www.nuget.org/packages/microsoft.aspnetcore.components.customelements). Custom elements use standard HTML interfaces to implement custom HTML elements. +Experimental support is available for building custom elements using the [`Microsoft.AspNetCore.Components.CustomElements` NuGet package](https://www.nuget.org/packages/microsoft.aspnetcore.components.customelements). Custom elements use standard HTML interfaces to implement custom HTML elements. Register a root component as a custom element: @@ -1741,7 +1741,7 @@ In the event a component must be updated based on an external event, such as a t Register the services: -* In a Blazor WebAssembly app, register the services as singletons in `Program.Main`: +* In a Blazor WebAssembly app, register the services as singletons in `Program.cs`: ```csharp builder.Services.AddSingleton(); @@ -2686,7 +2686,7 @@ In the event a component must be updated based on an external event, such as a t Register the services: -* In a Blazor WebAssembly app, register the services as singletons in `Program.Main`: +* In a Blazor WebAssembly app, register the services as singletons in `Program.cs`: ```csharp builder.Services.AddSingleton(); diff --git a/aspnetcore/blazor/components/prerendering-and-integration.md b/aspnetcore/blazor/components/prerendering-and-integration.md index a06b5429e61d..aebacd058c78 100644 --- a/aspnetcore/blazor/components/prerendering-and-integration.md +++ b/aspnetcore/blazor/components/prerendering-and-integration.md @@ -732,7 +732,7 @@ For more information, see . ## Preserve prerendered state -Without preserving prerendered state, any state that used during prerendering is lost and must be recreated when the app is fully loaded. If any state is setup asynchronously, the UI may flicker as the the prerendered UI is replaced with temporary placeholders and then fully rendered again. +Without preserving prerendered state, any state that used during prerendering is lost and must be recreated when the app is fully loaded. If any state is setup asynchronously, the UI may flicker as the prerendered UI is replaced with temporary placeholders and then fully rendered again. To solve these problems, Blazor supports persisting state in a prerendered page using the [Preserve Component State Tag Helper](xref:mvc/views/tag-helpers/builtin-th/preserve-component-state-tag-helper) (``). Add the `` tag inside the closing `` tag of `_Layout.cshtml`. @@ -866,7 +866,7 @@ To set up prerendering for a hosted Blazor WebAssembly app: 1. **Delete** the `wwwroot/index.html` file from the Blazor WebAssembly **`Client`** project. -1. In the **`Client`** project, **delete** the following line in `Program.Main` (`Program.cs`): +1. In the **`Client`** project, **delete** the following line in `Program.cs`: ```diff - builder.RootComponents.Add("#app"); @@ -1052,7 +1052,7 @@ Additional work might be required depending on the static resources that compone ## Render components in a page or view with a CSS selector -After [configuring the solution](#solution-configuration), including the [additional configuration](#configuration-for-embedding-razor-components-into-pages-and-views), add root components to the **`Client`** project of a hosted Blazor WebAssembly solution in `Program.Main`. In the following example, the `Counter` component is declared as a root component with a CSS selector that selects the element with the `id` that matches `counter-component`. In the following example, the **`Client`** project's namespace is `BlazorHosted.Client`. +After [configuring the solution](#solution-configuration), including the [additional configuration](#configuration-for-embedding-razor-components-into-pages-and-views), add root components to the **`Client`** project of a hosted Blazor WebAssembly solution in `Program.cs`. In the following example, the `Counter` component is declared as a root component with a CSS selector that selects the element with the `id` that matches `counter-component`. In the following example, the **`Client`** project's namespace is `BlazorHosted.Client`. In `Program.cs` of the **`Client`** project, add the namespace for the project's Razor components to the top of the file: @@ -1060,7 +1060,7 @@ In `Program.cs` of the **`Client`** project, add the namespace for the project's + using BlazorHosted.Client.Pages; ``` -After the `builder` is established in `Program.Main`, add the `Counter` component as a root component: +After the `builder` is established in `Program.cs`, add the `Counter` component as a root component: ```diff + builder.RootComponents.Add("#counter-component"); diff --git a/aspnetcore/blazor/debug.md b/aspnetcore/blazor/debug.md index 25e685eed297..46cdc101ea83 100644 --- a/aspnetcore/blazor/debug.md +++ b/aspnetcore/blazor/debug.md @@ -31,7 +31,7 @@ Available scenarios include: For now, you *can't*: * Break on unhandled exceptions. -* Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +* Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. * Debug in non-local scenarios (for example, [Windows Subsystem for Linux (WSL)](/windows/wsl/) or [Visual Studio Codespaces](/visualstudio/devinit/devinit-and-codespaces)). * Automatically rebuild the backend **`Server`** app of a hosted Blazor WebAssembly solution during debugging, for example by running the app with [`dotnet watch run`](xref:tutorials/dotnet-watch). @@ -102,7 +102,7 @@ While debugging a Blazor WebAssembly app, you can also debug server code: 1. Press F5 again to let execution continue and see the weather forecast table rendered in the browser. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. If the app is hosted at a different [app base path](xref:blazor/host-and-deploy/index#app-base-path) than `/`, update the following properties in `Properties/launchSettings.json` to reflect the app's base path: @@ -183,7 +183,7 @@ For information on configuring VS Code assets in the `.vscode` folder, see the * 1. In the browser, navigate to `Counter` page and select the **Click me** button to hit the breakpoint. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. ## Debug hosted Blazor WebAssembly @@ -276,7 +276,7 @@ While debugging a Blazor WebAssembly app, you can also debug server code: 1. Press + again to let execution continue and see the weather forecast table rendered in the browser. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. For more information, see [Debugging with Visual Studio for Mac](/visualstudio/mac/debugging). @@ -406,7 +406,7 @@ Available scenarios include: For now, you *can't*: * Break on unhandled exceptions. -* Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +* Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. * Debug in non-local scenarios (for example, [Windows Subsystem for Linux (WSL)](/windows/wsl/) or [Visual Studio Codespaces](/visualstudio/devinit/devinit-and-codespaces)). * Automatically rebuild the backend `*Server*` app of a hosted Blazor WebAssembly solution during debugging, for example by running the app with [`dotnet watch run`](xref:tutorials/dotnet-watch). @@ -477,7 +477,7 @@ While debugging a Blazor WebAssembly app, you can also debug server code: 1. Press F5 again to let execution continue and see the weather forecast table rendered in the browser. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. If the app is hosted at a different [app base path](xref:blazor/host-and-deploy/index#app-base-path) than `/`, update the following properties in `Properties/launchSettings.json` to reflect the app's base path: @@ -558,7 +558,7 @@ For information on configuring VS Code assets in the `.vscode` folder, see the * 1. In the browser, navigate to `Counter` page and select the **Click me** button to hit the breakpoint. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. ## Debug hosted Blazor WebAssembly @@ -699,7 +699,7 @@ While debugging a Blazor WebAssembly app, you can also debug server code: 1. Press + again to let execution continue and see the weather forecast table rendered in the browser. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. For more information, see [Debugging with Visual Studio for Mac](/visualstudio/mac/debugging). @@ -829,7 +829,7 @@ Available scenarios include: For now, you *can't*: * Break on unhandled exceptions. -* Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +* Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. * Debug in non-local scenarios (for example, [Windows Subsystem for Linux (WSL)](/windows/wsl/) or [Visual Studio Codespaces](/visualstudio/devinit/devinit-and-codespaces)). * Automatically rebuild the backend `*Server*` app of a hosted Blazor WebAssembly solution during debugging, for example by running the app with [`dotnet watch run`](xref:tutorials/dotnet-watch). @@ -900,7 +900,7 @@ While debugging a Blazor WebAssembly app, you can also debug server code: 1. Press F5 again to let execution continue and see the weather forecast table rendered in the browser. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. If the app is hosted at a different [app base path](xref:blazor/host-and-deploy/index#app-base-path) than `/`, update the following properties in `Properties/launchSettings.json` to reflect the app's base path: @@ -981,7 +981,7 @@ For information on configuring VS Code assets in the `.vscode` folder, see the * 1. In the browser, navigate to `Counter` page and select the **Click me** button to hit the breakpoint. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. ## Debug hosted Blazor WebAssembly @@ -1122,7 +1122,7 @@ While debugging a Blazor WebAssembly app, you can also debug server code: 1. Press + again to let execution continue and see the weather forecast table rendered in the browser. > [!NOTE] -> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.Main` (`Program.cs`) and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. +> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app. For more information, see [Debugging with Visual Studio for Mac](/visualstudio/mac/debugging). diff --git a/aspnetcore/blazor/file-uploads.md b/aspnetcore/blazor/file-uploads.md index f33a9202af56..3559295b32a5 100644 --- a/aspnetcore/blazor/file-uploads.md +++ b/aspnetcore/blazor/file-uploads.md @@ -142,10 +142,10 @@ The following example demonstrates uploading files from a Blazor Server app to a In the Blazor Server app, add and related services that allow the app to create instances. -In `Startup.ConfigureServices` of `Startup.cs`: +In `Program.cs`: ```csharp -services.AddHttpClient(); +builder.Services.AddHttpClient(); ``` For more information, see . diff --git a/aspnetcore/blazor/forms-validation.md b/aspnetcore/blazor/forms-validation.md index f2d35626424e..35a0ff1558f9 100644 --- a/aspnetcore/blazor/forms-validation.md +++ b/aspnetcore/blazor/forms-validation.md @@ -506,18 +506,18 @@ If the server API returns the preceding default JSON response, it's possible for } ``` -To modify the server API's response to make it only return the validation errors, change the delegate that's invoked on actions that are annotated with in `Startup.ConfigureServices`. For the API endpoint (`/StarshipValidation`), return a with the . For any other API endpoints, preserve the default behavior by returning the object result with a new . +To modify the server API's response to make it only return the validation errors, change the delegate that's invoked on actions that are annotated with in `Program.cs`. For the API endpoint (`/StarshipValidation`), return a with the . For any other API endpoints, preserve the default behavior by returning the object result with a new . -Add the namespace to the top of the `Startup.cs` file in the **`Server`** app: +Add the namespace to the top of the `Program.cs` file in the **`Server`** app: ```csharp using Microsoft.AspNetCore.Mvc; ``` -In `Startup.ConfigureServices`, locate the extension method and add the following call to : +In `Program.cs`, locate the extension method and add the following call to : ```csharp -services.AddControllersWithViews() +builder.Services.AddControllersWithViews() .ConfigureApiBehaviorOptions(options => { options.InvalidModelStateResponseFactory = context => @@ -2819,7 +2819,7 @@ The [`Microsoft.AspNetCore.Components.DataAnnotations.Validation`](https://www.n ## `[CompareProperty]` attribute -The doesn't work well with the component because it doesn't associate the validation result with a specific member. This can result in inconsistent behavior between field-level validation and when the entire model is validated on a submit. The [`Microsoft.AspNetCore.Components.DataAnnotations.Validation`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.DataAnnotations.Validation) *experimental* package introduces an additional validation attribute, `ComparePropertyAttribute`, that works around these limitations. In a Blazor app, `[CompareProperty]` is a direct replacement for the [`[Compare]` attribute](xref:System.ComponentModel.DataAnnotations.CompareAttribute). +The doesn't work well with the component because it doesn't associate the validation result with a specific member. This can result inconsistent behavior between field-level validation and when the entire model is validated on a submit. The [`Microsoft.AspNetCore.Components.DataAnnotations.Validation`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.DataAnnotations.Validation) *experimental* package introduces an additional validation attribute, `ComparePropertyAttribute`, that works around these limitations. In a Blazor app, `[CompareProperty]` is a direct replacement for the [`[Compare]` attribute](xref:System.ComponentModel.DataAnnotations.CompareAttribute). ## Nested models, collection types, and complex types diff --git a/aspnetcore/blazor/fundamentals/configuration.md b/aspnetcore/blazor/fundamentals/configuration.md index 9c844f6a66f6..19abdb41c330 100644 --- a/aspnetcore/blazor/fundamentals/configuration.md +++ b/aspnetcore/blazor/fundamentals/configuration.md @@ -78,7 +78,7 @@ Add the namespace for service registration to use the client to read the file: +In `Program.cs`, modify the existing service registration to use the client to read the file: ```csharp var http = new HttpClient() @@ -96,7 +96,7 @@ builder.Configuration.AddJsonStream(stream); ## Memory Configuration Source -The following example uses a in `Program.Main` to supply additional configuration. +The following example uses a in `Program.cs` to supply additional configuration. Add the namespace for to `Program.cs`: @@ -104,7 +104,7 @@ Add the namespace for () @@ -178,7 +178,7 @@ Provide authentication configuration in an app settings file. } ``` -Load the configuration for an Identity provider with in `Program.Main`. The following example loads configuration for an [OIDC provider](xref:blazor/security/webassembly/standalone-with-authentication-library). +Load the configuration for an Identity provider with in `Program.cs`. The following example loads configuration for an [OIDC provider](xref:blazor/security/webassembly/standalone-with-authentication-library). `Program.cs`: @@ -197,7 +197,7 @@ Add a package reference for [`Microsoft.Extensions.Logging.Configuration`](https In the preceding example, the `{VERSION}` placeholder is the package's version. Package versions are found at [NuGet.org](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Configuration). -In the app settings file, provide logging configuration. The logging configuration is loaded in `Program.Main`. +In the app settings file, provide logging configuration. The logging configuration is loaded in `Program.cs`. `wwwroot/appsettings.json`: @@ -219,7 +219,7 @@ Add the namespace for in `Program.Main`. +Read host builder configuration from in `Program.cs`. -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp var hostname = builder.Configuration["HostName"]; @@ -314,7 +314,7 @@ Add the namespace for service registration to use the client to read the file: +In `Program.cs`, modify the existing service registration to use the client to read the file: ```csharp var http = new HttpClient() @@ -332,7 +332,7 @@ builder.Configuration.AddJsonStream(stream); ## Memory Configuration Source -The following example uses a in `Program.Main` to supply additional configuration. +The following example uses a in `Program.cs` to supply additional configuration. Add the namespace for to `Program.cs`: @@ -340,7 +340,7 @@ Add the namespace for () @@ -414,7 +414,7 @@ Provide authentication configuration in an app settings file. } ``` -Load the configuration for an Identity provider with in `Program.Main`. The following example loads configuration for an [OIDC provider](xref:blazor/security/webassembly/standalone-with-authentication-library). +Load the configuration for an Identity provider with in `Program.cs`. The following example loads configuration for an [OIDC provider](xref:blazor/security/webassembly/standalone-with-authentication-library). `Program.cs`: @@ -433,7 +433,7 @@ Add a package reference for [`Microsoft.Extensions.Logging.Configuration`](https In the preceding example, the `{VERSION}` placeholder is the package's version. Package versions are found at [NuGet.org](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Configuration). -In the app settings file, provide logging configuration. The logging configuration is loaded in `Program.Main`. +In the app settings file, provide logging configuration. The logging configuration is loaded in `Program.cs`. `wwwroot/appsettings.json`: @@ -455,7 +455,7 @@ Add the namespace for in `Program.Main`. +Read host builder configuration from in `Program.cs`. -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp var hostname = builder.Configuration["HostName"]; @@ -550,7 +550,7 @@ Add the namespace for service registration to use the client to read the file: +In `Program.cs`, modify the existing service registration to use the client to read the file: ```csharp var http = new HttpClient() @@ -568,7 +568,7 @@ builder.Configuration.AddJsonStream(stream); ## Memory Configuration Source -The following example uses a in `Program.Main` to supply additional configuration. +The following example uses a in `Program.cs` to supply additional configuration. Add the namespace for to `Program.cs`: @@ -576,7 +576,7 @@ Add the namespace for () @@ -650,7 +650,7 @@ Provide authentication configuration in an app settings file. } ``` -Load the configuration for an Identity provider with in `Program.Main`. The following example loads configuration for an [OIDC provider](xref:blazor/security/webassembly/standalone-with-authentication-library). +Load the configuration for an Identity provider with in `Program.cs`. The following example loads configuration for an [OIDC provider](xref:blazor/security/webassembly/standalone-with-authentication-library). `Program.cs`: @@ -669,7 +669,7 @@ Add a package reference for [`Microsoft.Extensions.Logging.Configuration`](https In the preceding example, the `{VERSION}` placeholder is the package's version. Package versions are found at [NuGet.org](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Configuration). -In the app settings file, provide logging configuration. The logging configuration is loaded in `Program.Main`. +In the app settings file, provide logging configuration. The logging configuration is loaded in `Program.cs`. `wwwroot/appsettings.json`: @@ -691,7 +691,7 @@ Add the namespace for in `Program.Main`. +Read host builder configuration from in `Program.cs`. -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp var hostname = builder.Configuration["HostName"]; diff --git a/aspnetcore/blazor/fundamentals/dependency-injection.md b/aspnetcore/blazor/fundamentals/dependency-injection.md index d5d40ff2f854..9dcdea5ad9cc 100644 --- a/aspnetcore/blazor/fundamentals/dependency-injection.md +++ b/aspnetcore/blazor/fundamentals/dependency-injection.md @@ -37,92 +37,68 @@ A custom service provider doesn't automatically provide the default services lis ::: zone pivot="webassembly" -Configure services for the app's service collection in the `Program.Main` method of `Program.cs`. In the following example, the `MyDependency` implementation is registered for `IMyDependency`: +Configure services for the app's service collection in `Program.cs`. In the following example, the `MyDependency` implementation is registered for `IMyDependency`: ```csharp -public class Program -{ - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - ... - builder.Services.AddSingleton(); - ... +var builder = WebAssemblyHostBuilder.CreateDefault(args); +... +builder.Services.AddSingleton(); +... - await builder.Build().RunAsync(); - } -} +await builder.Build().RunAsync(); ``` After the host is built, services are available from the root DI scope before any components are rendered. This can be useful for running initialization logic before rendering content: ```csharp -public class Program -{ - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - ... - builder.Services.AddSingleton(); - ... +var builder = WebAssemblyHostBuilder.CreateDefault(args); +... +builder.Services.AddSingleton(); +... - var host = builder.Build(); +var host = builder.Build(); - var weatherService = host.Services.GetRequiredService(); - await weatherService.InitializeWeatherAsync(); +var weatherService = host.Services.GetRequiredService(); +await weatherService.InitializeWeatherAsync(); - await host.RunAsync(); - } -} +await host.RunAsync(); ``` The host provides a central configuration instance for the app. Building on the preceding example, the weather service's URL is passed from a default configuration source (for example, `appsettings.json`) to `InitializeWeatherAsync`: ```csharp -public class Program -{ - public static async Task Main(string[] args) - { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - ... - builder.Services.AddSingleton(); - ... +var builder = WebAssemblyHostBuilder.CreateDefault(args); +... +builder.Services.AddSingleton(); +... - var host = builder.Build(); +var host = builder.Build(); - var weatherService = host.Services.GetRequiredService(); - await weatherService.InitializeWeatherAsync( - host.Configuration["WeatherServiceUrl"]); +var weatherService = host.Services.GetRequiredService(); +await weatherService.InitializeWeatherAsync( + host.Configuration["WeatherServiceUrl"]); - await host.RunAsync(); - } -} +await host.RunAsync(); ``` ::: zone-end ::: zone pivot="server" -After creating a new app, examine the `Startup.ConfigureServices` method in `Startup.cs`: +After creating a new app, examine part of the `Program.cs` file: ```csharp -using Microsoft.Extensions.DependencyInjection; +var builder = WebApplication.CreateBuilder(args); -... - -public void ConfigureServices(IServiceCollection services) -{ - ... -} +builder.Services.AddRazorPages(); +builder.Services.AddServerSideBlazor(); +builder.Services.AddSingleton(); ``` -The method is passed an , which is a list of [service descriptor](xref:Microsoft.Extensions.DependencyInjection.ServiceDescriptor) objects. Services are added in the `ConfigureServices` method by providing service descriptors to the service collection. The following example demonstrates the concept with the `IDataAccess` interface and its concrete implementation `DataAccess`: +The `builder` variable represents an with an , which is a list of [service descriptor](xref:Microsoft.Extensions.DependencyInjection.ServiceDescriptor) objects. Services are added by providing service descriptors to the service collection. The following example demonstrates the concept with the `IDataAccess` interface and its concrete implementation `DataAccess`: ```csharp -public void ConfigureServices(IServiceCollection services) -{ - services.AddSingleton(); -} +builder.Services.AddSingleton(); ``` ::: zone-end @@ -253,27 +229,25 @@ The following examples show how to detect disposable transient services in an ap The `TransientDisposable` in the following example is detected (`Program.cs`): ```csharp -public class Program -{ - public static async Task Main(string[] args) +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.DetectIncorrectUsageOfTransients(); +builder.RootComponents.Add("#app"); + +builder.Services.AddTransient(); +builder.Services.AddScoped(sp => + new HttpClient { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.DetectIncorrectUsageOfTransients(); - builder.RootComponents.Add("#app"); + BaseAddress = new(builder.HostEnvironment.BaseAddress) + }); - builder.Services.AddTransient(); - builder.Services.AddScoped(sp => - new HttpClient - { - BaseAddress = new(builder.HostEnvironment.BaseAddress) - }); +var host = builder.Build(); +host.EnableTransientDisposableDetection(); +await host.RunAsync(); +``` - var host = builder.Build(); - host.EnableTransientDisposableDetection(); - await host.RunAsync(); - } -} +`TransientDisposable.cs`: +```csharp public class TransientDisposable : IDisposable { public void Dispose() => throw new NotImplementedException(); @@ -288,37 +262,15 @@ public class TransientDisposable : IDisposable [!code-csharp[](~/blazor/samples/6.0/BlazorSample_Server/dependency-injection/DetectIncorrectUsagesOfTransientDisposables.cs)] -Add the namespace for to `Program.cs`: - -```csharp -using Microsoft.Extensions.DependencyInjection; -``` - -In `Program.CreateHostBuilder` of `Program.cs`: +In `Program.cs`: ```csharp -public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .DetectIncorrectUsageOfTransients() - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); +app.DetectIncorrectUsageOfTransients(); ``` -The `TransientDependency` in the following example is detected (`Startup.cs`): +`TransitiveTransientDisposableDependency.cs`: ```csharp -public void ConfigureServices(IServiceCollection services) -{ - services.AddRazorPages(); - services.AddServerSideBlazor(); - services.AddSingleton(); - services.AddTransient(); - services.AddTransient(); -} - public class TransitiveTransientDisposableDependency : ITransitiveTransientDisposableDependency, IDisposable { @@ -343,6 +295,17 @@ public class TransientDependency } ``` +The `TransientDependency` in the following example is detected (`Program.cs`): + +```csharp +builder.Services.AddRazorPages(); +builder.Services.AddServerSideBlazor(); +builder.Services.AddSingleton(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +``` + ::: zone-end The app can register transient disposables without throwing an exception. However, attempting to resolve a transient disposable results in an , as the following example shows. @@ -391,7 +354,7 @@ A custom service provider doesn't automatically provide the default services lis ::: zone pivot="webassembly" -Configure services for the app's service collection in the `Program.Main` method of `Program.cs`. In the following example, the `MyDependency` implementation is registered for `IMyDependency`: +Configure services for the app's service collection in `Program.cs`. In the following example, the `MyDependency` implementation is registered for `IMyDependency`: ```csharp public class Program @@ -745,7 +708,7 @@ A custom service provider doesn't automatically provide the default services lis ::: zone pivot="webassembly" -Configure services for the app's service collection in the `Program.Main` method of `Program.cs`. In the following example, the `MyDependency` implementation is registered for `IMyDependency`: +Configure services for the app's service collection in `Program.cs`. In the following example, the `MyDependency` implementation is registered for `IMyDependency`: ```csharp public class Program diff --git a/aspnetcore/blazor/fundamentals/environments.md b/aspnetcore/blazor/fundamentals/environments.md index f06565b33a46..82247bc7e403 100644 --- a/aspnetcore/blazor/fundamentals/environments.md +++ b/aspnetcore/blazor/fundamentals/environments.md @@ -81,7 +81,7 @@ Obtain the app's environment in a component by injecting exposes the through the property, which enables environment-specific logic in host builder code. -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp if (builder.HostEnvironment.Environment == "Custom") @@ -97,7 +97,7 @@ The following convenience extension methods provided through * -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp if (builder.HostEnvironment.IsStaging()) @@ -190,7 +190,7 @@ Obtain the app's environment in a component by injecting exposes the through the property, which enables environment-specific logic in host builder code. -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp if (builder.HostEnvironment.Environment == "Custom") @@ -206,7 +206,7 @@ The following convenience extension methods provided through * -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp if (builder.HostEnvironment.IsStaging()) @@ -273,7 +273,7 @@ Obtain the app's environment in a component by injecting exposes the through the property, which enables environment-specific logic in host builder code. -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp if (builder.HostEnvironment.Environment == "Custom") @@ -289,7 +289,7 @@ The following convenience extension methods provided through * -In `Program.Main` of `Program.cs`: +In `Program.cs`: ```csharp if (builder.HostEnvironment.IsStaging()) diff --git a/aspnetcore/blazor/fundamentals/handle-errors.md b/aspnetcore/blazor/fundamentals/handle-errors.md index 19dd11a77126..ddddc449d95c 100644 --- a/aspnetcore/blazor/fundamentals/handle-errors.md +++ b/aspnetcore/blazor/fundamentals/handle-errors.md @@ -177,7 +177,7 @@ For more information, see the following articles: Components can be nested recursively. This is useful for representing recursive data structures. For example, a `TreeNode` component can render more `TreeNode` components for each of the node's children. -When rendering recursively, avoid coding patterns that result in infinite recursion: +When rendering recursively, avoid coding patterns that result infinite recursion: * Don't recursively render a data structure that contains a cycle. For example, don't render a tree node whose children includes itself. * Don't create a chain of layouts that contain a cycle. For example, don't create a layout whose layout is itself. @@ -455,7 +455,7 @@ To tolerate errors that may occur during prerendering, error handling logic must Components can be nested recursively. This is useful for representing recursive data structures. For example, a `TreeNode` component can render more `TreeNode` components for each of the node's children. -When rendering recursively, avoid coding patterns that result in infinite recursion: +When rendering recursively, avoid coding patterns that result infinite recursion: * Don't recursively render a data structure that contains a cycle. For example, don't render a tree node whose children includes itself. * Don't create a chain of layouts that contain a cycle. For example, don't create a layout whose layout is itself. @@ -663,7 +663,7 @@ For more information, see the following articles: Components can be nested recursively. This is useful for representing recursive data structures. For example, a `TreeNode` component can render more `TreeNode` components for each of the node's children. -When rendering recursively, avoid coding patterns that result in infinite recursion: +When rendering recursively, avoid coding patterns that result infinite recursion: * Don't recursively render a data structure that contains a cycle. For example, don't render a tree node whose children includes itself. * Don't create a chain of layouts that contain a cycle. For example, don't create a layout whose layout is itself. @@ -939,7 +939,7 @@ To tolerate errors that may occur during prerendering, error handling logic must Components can be nested recursively. This is useful for representing recursive data structures. For example, a `TreeNode` component can render more `TreeNode` components for each of the node's children. -When rendering recursively, avoid coding patterns that result in infinite recursion: +When rendering recursively, avoid coding patterns that result infinite recursion: * Don't recursively render a data structure that contains a cycle. For example, don't render a tree node whose children includes itself. * Don't create a chain of layouts that contain a cycle. For example, don't create a layout whose layout is itself. @@ -1147,7 +1147,7 @@ For more information, see the following articles: Components can be nested recursively. This is useful for representing recursive data structures. For example, a `TreeNode` component can render more `TreeNode` components for each of the node's children. -When rendering recursively, avoid coding patterns that result in infinite recursion: +When rendering recursively, avoid coding patterns that result infinite recursion: * Don't recursively render a data structure that contains a cycle. For example, don't render a tree node whose children includes itself. * Don't create a chain of layouts that contain a cycle. For example, don't create a layout whose layout is itself. @@ -1423,7 +1423,7 @@ To tolerate errors that may occur during prerendering, error handling logic must Components can be nested recursively. This is useful for representing recursive data structures. For example, a `TreeNode` component can render more `TreeNode` components for each of the node's children. -When rendering recursively, avoid coding patterns that result in infinite recursion: +When rendering recursively, avoid coding patterns that result infinite recursion: * Don't recursively render a data structure that contains a cycle. For example, don't render a tree node whose children includes itself. * Don't create a chain of layouts that contain a cycle. For example, don't create a layout whose layout is itself. diff --git a/aspnetcore/blazor/fundamentals/logging.md b/aspnetcore/blazor/fundamentals/logging.md index 606139c6b156..f891933fccc1 100644 --- a/aspnetcore/blazor/fundamentals/logging.md +++ b/aspnetcore/blazor/fundamentals/logging.md @@ -24,7 +24,7 @@ Add the namespace for and add the custom logging provider: +In `Program.cs`, set the minimum logging level with and add the custom logging provider: ```csharp var builder = WebAssemblyHostBuilder.CreateDefault(args); @@ -108,7 +108,7 @@ Add the namespace for and add the custom logging provider: +In `Program.cs`, set the minimum logging level with and add the custom logging provider: ```csharp var builder = WebAssemblyHostBuilder.CreateDefault(args); @@ -192,7 +192,7 @@ Add the namespace for and add the custom logging provider: +In `Program.cs`, set the minimum logging level with and add the custom logging provider: ```csharp var builder = WebAssemblyHostBuilder.CreateDefault(args); diff --git a/aspnetcore/blazor/fundamentals/routing.md b/aspnetcore/blazor/fundamentals/routing.md index 3ed2f2a0a4ed..2a181a0fbe93 100644 --- a/aspnetcore/blazor/fundamentals/routing.md +++ b/aspnetcore/blazor/fundamentals/routing.md @@ -177,20 +177,16 @@ Consider the following `Example` component that can receive a route parameter fr [!code-razor[](~/blazor/samples/6.0/BlazorSample_WebAssembly/Pages/routing/Example.razor?highlight=1)] -To permit the **`Server`** app of a hosted Blazor WebAssembly solution to route the request with a dot in the `param` route parameter, add a fallback file route template with the optional parameter in `Startup.Configure`. - -`Startup.cs`: +To permit the **`Server`** app of a hosted Blazor WebAssembly solution to route the request with a dot in the `param` route parameter, add a fallback file route template with the optional parameter in `Program.cs`: ```csharp -endpoints.MapFallbackToFile("/example/{param?}", "index.html"); +app.MapFallbackToFile("/example/{param?}", "index.html"); ``` -To configure a Blazor Server app to route the request with a dot in the `param` route parameter, add a fallback page route template with the optional parameter in `Startup.Configure`. - -`Startup.cs`: +To configure a Blazor Server app to route the request with a dot in the `param` route parameter, add a fallback page route template with the optional parameter in `Program.cs`: ```csharp -endpoints.MapFallbackToPage("/example/{param?}", "/_Host"); +app.MapFallbackToPage("/example/{param?}", "/_Host"); ``` For more information, see . @@ -645,11 +641,9 @@ The following HTML markup is rendered: *This section only applies to Blazor Server apps.* -Blazor Server is integrated into [ASP.NET Core Endpoint Routing](xref:fundamentals/routing). An ASP.NET Core app is configured to accept incoming connections for interactive components with in `Startup.Configure`. - -`Startup.cs`: +Blazor Server is integrated into [ASP.NET Core Endpoint Routing](xref:fundamentals/routing). An ASP.NET Core app is configured to accept incoming connections for interactive components with in `Program.cs`: -[!code-csharp[](~/blazor/samples/6.0/BlazorSample_Server/routing/Startup.cs?highlight=11)] +[!code-csharp[](~/blazor/samples/6.0/BlazorSample_Server/routing/Program.cs)] The typical configuration is to route all requests to a Razor page, which acts as the host for the server-side part of the Blazor Server app. By convention, the *host* page is usually named `_Host.cshtml` in the `Pages` folder of the app. diff --git a/aspnetcore/blazor/fundamentals/signalr.md b/aspnetcore/blazor/fundamentals/signalr.md index 604c9fc0361e..43a90f73ce62 100644 --- a/aspnetcore/blazor/fundamentals/signalr.md +++ b/aspnetcore/blazor/fundamentals/signalr.md @@ -96,12 +96,12 @@ Configure the Blazor Server circuit with the | 1 minute | Maximum amount of time the server waits before timing out an asynchronous JavaScript function invocation. | | | 10 | Maximum number of unacknowledged render batches the server keeps in memory per circuit at a given time to support robust reconnection. After reaching the limit, the server stops producing new render batches until one or more batches are acknowledged by the client. | -Configure the options in `Startup.ConfigureServices` with an options delegate to . The following example assigns the default option values shown in the preceding table. Confirm that `Startup.cs` uses the namespace (`using System;`). +Configure the options in `Program.cs` with an options delegate to . The following example assigns the default option values shown in the preceding table. Confirm that `Program.cs` uses the namespace (`using System;`). -`Startup.ConfigureServices`: +In `Program.cs`: ```csharp -services.AddServerSideBlazor(options => +builder.Services.AddServerSideBlazor(options => { options.DetailedErrors = false; options.DisconnectedCircuitMaxRetained = 100; @@ -111,12 +111,12 @@ services.AddServerSideBlazor(options => }); ``` -To configure the , use with . For option descriptions, see . The following example assigns the default option values. Confirm that `Startup.cs` uses the namespace (`using System;`). +To configure the , use with . For option descriptions, see . The following example assigns the default option values. Confirm that `Program.cs` uses the namespace (`using System;`). -`Startup.ConfigureServices`: +In `Program.cs`: ```csharp -services.AddServerSideBlazor() +builder.Services.AddServerSideBlazor() .AddHubOptions(options => { options.ClientTimeoutInterval = TimeSpan.FromSeconds(30); @@ -131,7 +131,7 @@ services.AddServerSideBlazor() ## Blazor Hub endpoint route configuration -In `Startup.Configure`, Blazor Server apps call on the of to map the Blazor to the app's default path. The Blazor Server script (`blazor.server.js`) automatically points to the endpoint created by . +In `Program.cs`, Blazor Server apps call to map the Blazor to the app's default path. The Blazor Server script (`blazor.server.js`) automatically points to the endpoint created by . ## Reflect the connection state in the UI @@ -332,14 +332,10 @@ Blazor Server allows code to define a *circuit handler*, which allows running co Circuit handlers are registered using DI. Scoped instances are created per instance of a circuit. Using the `TrackingCircuitHandler` in the preceding example, a singleton service is created because the state of all circuits must be tracked. -`Startup.cs`: +`Program.cs`: ```csharp -public void ConfigureServices(IServiceCollection services) -{ - ... - services.AddSingleton(); -} +builder.Services.AddSingleton(); ``` If a custom circuit handler's methods throw an unhandled exception, the exception is fatal to the Blazor Server circuit. To tolerate exceptions in a handler's code or called methods, wrap the code in one or more [`try-catch`](/dotnet/csharp/language-reference/keywords/try-catch) statements with error handling and logging. @@ -354,10 +350,10 @@ We recommend using the [Azure SignalR Service](xref:signalr/scale#azure-signalr- In earlier versions of ASP.NET Core, Long Polling was enabled as a fallback transport for situations in which the WebSockets transport wasn't available. If an app must use Long Polling, make the following changes: -In the app's `Startup.cs` file, replace `endpoints.MapBlazorHub()` with the following code: +In the app's `Program.cs` file, replace `app.MapBlazorHub()` with the following code: ```csharp -endpoints.MapBlazorHub(configureOptions: options => +app.MapBlazorHub(configureOptions: options => { options.Transports = HttpTransportType.WebSockets | HttpTransportType.LongPolling; diff --git a/aspnetcore/blazor/fundamentals/static-files.md b/aspnetcore/blazor/fundamentals/static-files.md index bf9a9355b09c..ab7ff6d9558d 100644 --- a/aspnetcore/blazor/fundamentals/static-files.md +++ b/aspnetcore/blazor/fundamentals/static-files.md @@ -17,7 +17,7 @@ uid: blazor/fundamentals/static-files To create additional file mappings with a or configure other , use **one** of the following approaches. In the following examples, the `{EXTENSION}` placeholder is the file extension, and the `{CONTENT TYPE}` placeholder is the content type. -* Configure options through [dependency injection (DI)](xref:blazor/fundamentals/dependency-injection) in `Startup.ConfigureServices` (`Startup.cs`) using : +* Configure options through [dependency injection (DI)](xref:blazor/fundamentals/dependency-injection) in `Program.cs` using : ```csharp using Microsoft.AspNetCore.StaticFiles; @@ -27,7 +27,7 @@ To create additional file mappings with a (options => + builder.Services.Configure(options => { options.ContentTypeProvider = provider; }); @@ -35,7 +35,7 @@ To create additional file mappings with a in `Startup.Configure` (`Startup.cs`): +* Use two calls to in `Program.cs`: * Configure the custom file provider in the first call with . * The second middleware serves `blazor.server.js`, which uses the default static files configuration provided by the Blazor framework. diff --git a/aspnetcore/blazor/globalization-localization.md b/aspnetcore/blazor/globalization-localization.md index 1a4f0823f790..875a6e1256de 100644 --- a/aspnetcore/blazor/globalization-localization.md +++ b/aspnetcore/blazor/globalization-localization.md @@ -183,13 +183,13 @@ Set the `BlazorWebAssemblyLoadAllGlobalizationData` property to `true` in the ap Blazor Server apps are localized using [Localization Middleware](xref:fundamentals/localization#localization-middleware). Add localization services to the app with . -In `Startup.ConfigureServices` (`Startup.cs`): +In `Program.cs`: ```csharp -services.AddLocalization(); +builder.Services.AddLocalization(); ``` -Specify the app's supported cultures in `Startup.Configure` (`Startup.cs`) immediately after Routing Middleware is added to the processing pipeline. The following example configures supported cultures for United States English and Chilean Spanish: +Specify the app's supported cultures in `Program.cs` immediately after Routing Middleware is added to the processing pipeline. The following example configures supported cultures for United States English and Chilean Spanish: ```csharp app.UseRequestLocalization(new RequestLocalizationOptions() @@ -197,7 +197,7 @@ app.UseRequestLocalization(new RequestLocalizationOptions() .AddSupportedUICultures(new[] { "en-US", "es-CL" })); ``` -For information on ordering the Localization Middleware in the middleware pipeline of `Startup.Configure`, see . +For information on ordering the Localization Middleware in the middleware pipeline of `Program.cs`, see . ::: zone-end @@ -248,7 +248,7 @@ The app's culture can be set in JavaScript when Blazor starts with the `applicat The value for `applicationCulture` must conform to the [BCP-47 language tag format](https://www.rfc-editor.org/info/bcp47). For more information on Blazor startup, see . -An alternative to setting the culture Blazor's start option is to set the culture in C# code. Set and in `Program.Main` (`Program.cs`). +An alternative to setting the culture Blazor's start option is to set the culture in C# code. Set and in `Program.cs`. Add the namespace to `Program.cs`: @@ -269,13 +269,13 @@ CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US"); Blazor Server apps are localized using [Localization Middleware](xref:fundamentals/localization#localization-middleware). Add localization services to the app with . -In `Startup.ConfigureServices` (`Startup.cs`): +In `Program.cs`: ```csharp -services.AddLocalization(); +builder.Services.AddLocalization(); ``` -Specify the static culture in `Startup.Configure` (`Startup.cs`) immediately after Routing Middleware is added to the processing pipeline. The following example configures United States English: +Specify the static culture in `Program.cs` immediately after Routing Middleware is added to the processing pipeline. The following example configures United States English: ```csharp app.UseRequestLocalization("en-US"); @@ -283,7 +283,7 @@ app.UseRequestLocalization("en-US"); The culture value for must conform to the [BCP-47 language tag format](https://www.rfc-editor.org/info/bcp47). -For information on ordering the Localization Middleware in the middleware pipeline of `Startup.Configure`, see . +For information on ordering the Localization Middleware in the middleware pipeline of `Program.cs`, see . ::: zone-end @@ -347,10 +347,10 @@ using System.Globalization; using Microsoft.JSInterop; ``` -Remove the following line from `Program.Main`: +Remove the following line from `Program.cs`: ```diff --await builder.Build().RunAsync(); +- await builder.Build().RunAsync(); ``` Replace the preceding line with the following code. The code adds Blazor's localization service to the app's service collection with and uses [JS interop](xref:blazor/js-interop/call-javascript-from-dotnet) to call into JS and retrieve the user's culture selection from local storage. If local storage doesn't contain a culture for the user, the code sets a default value of United States English (`en-US`). @@ -452,15 +452,15 @@ The `{VERSION}` placeholder in the preceding package reference is the version of Blazor Server apps are localized using [Localization Middleware](xref:fundamentals/localization#localization-middleware). Add localization services to the app with . -In `Startup.ConfigureServices` (`Startup.cs`): +In `Program.cs`: ```csharp -services.AddLocalization(); +builder.Services.AddLocalization(); ``` Set the app's default and supported cultures with . -In `Startup.Configure` immediately after Routing Middleware is added to the processing pipeline: +In `Program.cs` immediately after Routing Middleware is added to the processing pipeline: ```csharp var supportedCultures = new[] { "en-US", "es-CL" }; @@ -472,7 +472,7 @@ var localizationOptions = new RequestLocalizationOptions() app.UseRequestLocalization(localizationOptions); ``` -For information on ordering the Localization Middleware in the middleware pipeline of `Startup.Configure`, see . +For information on ordering the Localization Middleware in the middleware pipeline of `Program.cs`, see . The following example shows how to set the current culture in a cookie that can be read by the Localization Middleware. @@ -496,31 +496,28 @@ Immediately after the opening `` tag of `Pages/_Layout.cshtml`, add the fo } ``` -For information on ordering the Localization Middleware in the middleware pipeline of `Startup.Configure`, see . +For information on ordering the Localization Middleware in the middleware pipeline of `Program.cs`, see . If the app isn't configured to process controller actions: -* Add MVC services by calling on the service collection in `Startup.ConfigureServices`: +* Add MVC services by calling on the service collection in `Program.cs`: ```csharp - services.AddControllers(); + builder.Services.AddControllers(); ``` -* Add controller endpoint routing in `Startup.Configure` by calling on the : +* Add controller endpoint routing in `Program.cs` by calling on the : ```csharp - endpoints.MapControllers(); + app.MapControllers(); ``` The following example shows the call to after the line is added: - ```diff - app.UseEndpoints(endpoints => - { - + endpoints.MapControllers(); - endpoints.MapBlazorHub(); - endpoints.MapFallbackToPage("/_Host"); - }); + ```csharp + app.MapControllers(); + app.MapBlazorHub(); + app.MapFallbackToPage("/_Host"); ``` To provide UI to allow a user to select a culture, use a *redirect-based approach* with a localization cookie. The app persists the user's selected culture via a redirect to a controller. The controller sets the user's selected culture into a cookie and redirects the user back to the original URI. The process is similar to what happens in a web app when a user attempts to access a secure resource, where the user is redirected to a sign-in page and then redirected back to the original resource. @@ -638,13 +635,13 @@ Set the `BlazorWebAssemblyLoadAllGlobalizationData` property to `true` in the ap ``` -In `Program.Main` (`Program.cs`), add namespace the namespace for to the top of the file: +In `Program.cs`, add namespace the namespace for to the top of the file: ```csharp using System.Globalization; ``` -Add Blazor's localization service to the app's service collection with in `Program.Main`: +Add Blazor's localization service to the app's service collection with in `Program.cs`: ```csharp builder.Services.AddLocalization(); @@ -659,15 +656,15 @@ Use [Localization Middleware](xref:fundamentals/localization#localization-middle If the app doesn't already support culture selection per the [Dynamically set the culture by user preference](#dynamically-set-the-culture-by-user-preference) section of this article: * Add localization services to the app with . -* Specify the app's default and supported cultures in `Startup.Configure` (`Startup.cs`). The following example configures supported cultures for United States English and Chilean Spanish. +* Specify the app's default and supported cultures in `Program.cs`. The following example configures supported cultures for United States English and Chilean Spanish. -In `Startup.ConfigureServices` (`Startup.cs`): +In `Program.cs`: ```csharp -services.AddLocalization(); +builder.Services.AddLocalization(); ``` -In `Startup.Configure` immediately after Routing Middleware is added to the processing pipeline: +In `Program.cs` immediately after Routing Middleware is added to the processing pipeline: ```csharp var supportedCultures = new[] { "en-US", "es-CL" }; @@ -679,7 +676,7 @@ var localizationOptions = new RequestLocalizationOptions() app.UseRequestLocalization(localizationOptions); ``` -For information on ordering the Localization Middleware in the middleware pipeline of `Startup.Configure`, see . +For information on ordering the Localization Middleware in the middleware pipeline of `Program.cs`, see . If the app should localize resources based on storing a user's culture setting, use a localization culture cookie. Use of a cookie ensures that the WebSocket connection can correctly propagate the culture. If localization schemes are based on the URL path or query string, the scheme might not be able to work with [WebSockets](xref:fundamentals/websockets), thus fail to persist the culture. Therefore, the recommended approach is to use a localization culture cookie. See the [Dynamically set the culture by user preference](#dynamically-set-the-culture-by-user-preference) section of this article to see an example Razor expression for the `Pages/_Layout.cshtml` file that persists the user's culture selection. @@ -1134,7 +1131,7 @@ The app's culture can be set in JavaScript when Blazor starts with the `applicat The value for `applicationCulture` must conform to the [BCP-47 language tag format](https://www.rfc-editor.org/info/bcp47). For more information on Blazor startup, see . -An alternative to setting the culture Blazor's start option is to set the culture in C# code. Set and in `Program.Main` (`Program.cs`). +An alternative to setting the culture Blazor's start option is to set the culture in C# code. Set and in `Program.cs`. Add the namespace to `Program.cs`: @@ -1233,10 +1230,10 @@ using System.Globalization; using Microsoft.JSInterop; ``` -Remove the following line from `Program.Main`: +Remove the following line from `Program.cs`: ```diff --await builder.Build().RunAsync(); +- await builder.Build().RunAsync(); ``` Replace the preceding line with the following code. The code adds Blazor's localization service to the app's service collection with and uses [JS interop](xref:blazor/js-interop/call-javascript-from-dotnet) to call into JS and retrieve the user's culture selection from local storage. If local storage doesn't contain a culture for the user, the code sets a default value of United States English (`en-US`). @@ -1524,13 +1521,13 @@ Set the `BlazorWebAssemblyLoadAllGlobalizationData` property to `true` in the ap ``` -In `Program.Main` (`Program.cs`), add namespace the namespace for to the top of the file: +In `Program.cs`, add namespace the namespace for to the top of the file: ```csharp using System.Globalization; ``` -Add Blazor's localization service to the app's service collection with in `Program.Main`: +Add Blazor's localization service to the app's service collection with in `Program.cs`: ```csharp builder.Services.AddLocalization(); @@ -2042,7 +2039,7 @@ using System.Globalization; using Microsoft.JSInterop; ``` -Remove the following line from `Program.Main`: +Remove the following line from `Program.cs`: ```diff -await builder.Build().RunAsync(); @@ -2327,13 +2324,13 @@ The `{VERSION}` placeholder in the preceding package reference is the version of By default, the Intermediate Language (IL) Linker configuration for Blazor WebAssembly apps strips out internationalization information except for locales explicitly requested. For more information, see . -In `Program.Main` (`Program.cs`), add namespace the namespace for to the top of the file: +In `Program.cs`, add namespace the namespace for to the top of the file: ```csharp using System.Globalization; ``` -Add Blazor's localization service to the app's service collection with in `Program.Main`: +Add Blazor's localization service to the app's service collection with in `Program.cs`: ```csharp builder.Services.AddLocalization(); diff --git a/aspnetcore/blazor/host-and-deploy/index.md b/aspnetcore/blazor/host-and-deploy/index.md index 3f83aa1361ae..2572a00af9a2 100644 --- a/aspnetcore/blazor/host-and-deploy/index.md +++ b/aspnetcore/blazor/host-and-deploy/index.md @@ -76,7 +76,7 @@ Blazor Server (`Pages/_Layout.cshtml`): ``` -Blazor Server apps additionally set the server-side base path by calling in the app's request pipeline of `Startup.Configure`: +Blazor Server apps additionally set the server-side base path by calling in the app's request pipeline of `Program.cs`: ```csharp app.UsePathBase("/CoolApp"); @@ -104,16 +104,16 @@ The Blazor WebAssembly app responds locally at `http://localhost:port/CoolApp`. ### Blazor Server `MapFallbackToPage` configuration -Pass the following path to in `Startup.Configure`: +Pass the following path to in `Program.cs`: ```csharp -endpoints.MapFallbackToPage("/{RELATIVE PATH}/{**path:nonfile}"); +app.MapFallbackToPage("/{RELATIVE PATH}/{**path:nonfile}"); ``` The placeholder `{RELATIVE PATH}` is the non-root path on the server. For example, `CoolApp` is the placeholder segment if the non-root URL to the app is `https://{HOST}:{PORT}/CoolApp/`): ```csharp -endpoints.MapFallbackToPage("/CoolApp/{**path:nonfile}"); +app.MapFallbackToPage("/CoolApp/{**path:nonfile}"); ``` ### Host multiple Blazor WebAssembly apps diff --git a/aspnetcore/blazor/host-and-deploy/server.md b/aspnetcore/blazor/host-and-deploy/server.md index d86f95b9386d..de9a86e0c6b7 100644 --- a/aspnetcore/blazor/host-and-deploy/server.md +++ b/aspnetcore/blazor/host-and-deploy/server.md @@ -66,10 +66,10 @@ We recommend using the [Azure SignalR Service](xref:signalr/scale#azure-signalr- To configure an app for the Azure SignalR Service, the app must support *sticky sessions*, where clients are [redirected back to the same server when prerendering](xref:blazor/hosting-models#connection-to-the-server). The `ServerStickyMode` option or configuration value is set to `Required`. Typically, an app creates the configuration using **_ONE_** of the following approaches: -* `Startup.ConfigureServices`: +* `Program.cs`: ```csharp - services.AddSignalR().AddAzureSignalR(options => + builder.Services.AddSignalR().AddAzureSignalR(options => { options.ServerStickyMode = Microsoft.Azure.SignalR.ServerStickyMode.Required; diff --git a/aspnetcore/blazor/host-and-deploy/webassembly.md b/aspnetcore/blazor/host-and-deploy/webassembly.md index d05b8e1e62d6..d3fd14eca68e 100644 --- a/aspnetcore/blazor/host-and-deploy/webassembly.md +++ b/aspnetcore/blazor/host-and-deploy/webassembly.md @@ -43,7 +43,7 @@ To compile the app to WebAssembly, publish the app. Publishing the `Release` con dotnet publish -c Release ``` -WebAssembly AOT compilation is only performed when the the project is published. AOT compilation isn't used when the project is run during development (`Development` environment) because AOT compilation usually takes several minutes on small projects and potentially much longer for larger projects. Reducing the build time for AOT compilation is under development for future releases of ASP.NET Core. +WebAssembly AOT compilation is only performed when the project is published. AOT compilation isn't used when the project is run during development (`Development` environment) because AOT compilation usually takes several minutes on small projects and potentially much longer for larger projects. Reducing the build time for AOT compilation is under development for future releases of ASP.NET Core. The size of an AOT-compiled Blazor WebAssembly app is generally larger than the size of the app if compiled into .NET IL. Although the size difference depends on the app, most AOT-compiled apps are about twice the size of their IL-compiled versions. This means that using AOT compilation trades off load time performance for runtime performance. Whether this tradeoff is worth using AOT compilation depends on your app. Blazor WebAssembly apps that are CPU intensive generally benefit the most from AOT compilation. @@ -171,7 +171,7 @@ Hosted Blazor solutions can serve multiple Blazor WebAssembly apps. In the following example: * The initial (first) client app is the default client project of a solution created from the Blazor WebAssembly project template. The first client app is accessible in a browser from the URL `/FirstApp` on either port 5001 or with a host of `firstapp.com`. -* A second client app is added to the solution, `SecondBlazorApp.Client`. The second client app is accessible in a browser from the the URL `/SecondApp` on either port 5002 or with a host of `secondapp.com`. +* A second client app is added to the solution, `SecondBlazorApp.Client`. The second client app is accessible in a browser from the URL `/SecondApp` on either port 5002 or with a host of `secondapp.com`. Use an existing hosted Blazor solution or create a new solution from the Blazor Hosted project template: @@ -237,7 +237,7 @@ Use an existing hosted Blazor solution or create a new solution from the Blazor "applicationUrl": "https://localhost:5001;https://localhost:5002", ``` -* In the server app's `Startup.Configure` method (`Startup.cs`), remove the following lines, which appear after the call to : +* In the server app's `Program.cs` file, remove the following lines, which appear after the call to : ```csharp app.UseBlazorFrameworkFiles(); @@ -245,12 +245,9 @@ Use an existing hosted Blazor solution or create a new solution from the Blazor app.UseRouting(); - app.UseEndpoints(endpoints => - { - endpoints.MapRazorPages(); - endpoints.MapControllers(); - endpoints.MapFallbackToFile("index.html"); - }); + app.MapRazorPages(); + app.MapControllers(); + app.MapFallbackToFile("index.html"); ``` Add middleware that maps requests to the client apps. The following example configures the middleware to run when: @@ -321,7 +318,7 @@ Use an existing hosted Blazor solution or create a new solution from the Blazor [Route("SecondApp/[controller]")] ``` - The middleware added to the server app's `Startup.Configure` method earlier modifies incoming requests to `/WeatherForecast` to either `/FirstApp/WeatherForecast` or `/SecondApp/WeatherForecast` depending on the port (5001/5002) or domain (`firstapp.com`/`secondapp.com`). The preceding controller routes are required in order to return weather data from the server app to the client apps. + The middleware added to the server app's request processing pipeline earlier modifies incoming requests to `/WeatherForecast` to either `/FirstApp/WeatherForecast` or `/SecondApp/WeatherForecast` depending on the port (5001/5002) or domain (`firstapp.com`/`secondapp.com`). The preceding controller routes are required in order to return weather data from the server app to the client apps. ### Static assets and class libraries for multiple Blazor WebAssembly apps @@ -772,7 +769,7 @@ If you confirm that the server is returning plausibly correct data, there must b Use the [`integrity.ps1`](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/host-and-deploy/webassembly/_samples/integrity.ps1?raw=true) PowerShell script to validate a published and deployed Blazor app. The script is provided for PowerShell Core 6 as a starting point when the app has integrity issues that the Blazor framework can't identify. Customization of the script might be required for your apps, including if running on version of PowerShell later than version 6.2.7. -The script checks the files in the `publish` folder and downloaded from the deployed app to detect issues in the different manifests that contain integrity hashes. These checks should detect the most common problems: +The script checks the files in the `publish` folder and downloaded from the deployed app to detect issues in the different manifests that containtegrity hashes. These checks should detect the most common problems: * You modified a file in the published output without realizing it. * The app wasn't correctly deployed to the deployment target, or something changed within the deployment target's environment. @@ -978,7 +975,7 @@ Hosted Blazor solutions can serve multiple Blazor WebAssembly apps. In the following example: * The initial (first) client app is the default client project of a solution created from the Blazor WebAssembly project template. The first client app is accessible in a browser from the URL `/FirstApp` on either port 5001 or with a host of `firstapp.com`. -* A second client app is added to the solution, `SecondBlazorApp.Client`. The second client app is accessible in a browser from the the URL `/SecondApp` on either port 5002 or with a host of `secondapp.com`. +* A second client app is added to the solution, `SecondBlazorApp.Client`. The second client app is accessible in a browser from the URL `/SecondApp` on either port 5002 or with a host of `secondapp.com`. Use an existing hosted Blazor solution or create a new solution from the Blazor Hosted project template: @@ -1579,7 +1576,7 @@ If you confirm that the server is returning plausibly correct data, there must b Use the [`integrity.ps1`](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/host-and-deploy/webassembly/_samples/integrity.ps1?raw=true) PowerShell script to validate a published and deployed Blazor app. The script is provided for PowerShell Core 6 as a starting point when the app has integrity issues that the Blazor framework can't identify. Customization of the script might be required for your apps, including if running on version of PowerShell later than version 6.2.7. -The script checks the files in the `publish` folder and downloaded from the deployed app to detect issues in the different manifests that contain integrity hashes. These checks should detect the most common problems: +The script checks the files in the `publish` folder and downloaded from the deployed app to detect issues in the different manifests that containtegrity hashes. These checks should detect the most common problems: * You modified a file in the published output without realizing it. * The app wasn't correctly deployed to the deployment target, or something changed within the deployment target's environment. @@ -1785,7 +1782,7 @@ Hosted Blazor solutions can serve multiple Blazor WebAssembly apps. In the following example: * The initial (first) client app is the default client project of a solution created from the Blazor WebAssembly project template. The first client app is accessible in a browser from the URL `/FirstApp` on either port 5001 or with a host of `firstapp.com`. -* A second client app is added to the solution, `SecondBlazorApp.Client`. The second client app is accessible in a browser from the the URL `/SecondApp` on either port 5002 or with a host of `secondapp.com`. +* A second client app is added to the solution, `SecondBlazorApp.Client`. The second client app is accessible in a browser from the URL `/SecondApp` on either port 5002 or with a host of `secondapp.com`. Use an existing hosted Blazor solution or create a new solution from the Blazor Hosted project template: @@ -2386,7 +2383,7 @@ If you confirm that the server is returning plausibly correct data, there must b Use the [`integrity.ps1`](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/host-and-deploy/webassembly/_samples/integrity.ps1?raw=true) PowerShell script to validate a published and deployed Blazor app. The script is provided for PowerShell Core 6 as a starting point when the app has integrity issues that the Blazor framework can't identify. Customization of the script might be required for your apps, including if running on version of PowerShell later than version 6.2.7. -The script checks the files in the `publish` folder and downloaded from the deployed app to detect issues in the different manifests that contain integrity hashes. These checks should detect the most common problems: +The script checks the files in the `publish` folder and downloaded from the deployed app to detect issues in the different manifests that containtegrity hashes. These checks should detect the most common problems: * You modified a file in the published output without realizing it. * The app wasn't correctly deployed to the deployment target, or something changed within the deployment target's environment. diff --git a/aspnetcore/blazor/includes/js-interop/size-limits.md b/aspnetcore/blazor/includes/js-interop/size-limits.md index b0398dd27345..2f51c5e6b383 100644 --- a/aspnetcore/blazor/includes/js-interop/size-limits.md +++ b/aspnetcore/blazor/includes/js-interop/size-limits.md @@ -31,7 +31,14 @@ Error: > System.IO.InvalidDataException: The maximum message size of 32768B was exceeded. The message size can be configured in AddHubOptions. -Increase the limit by setting in `Startup.ConfigureServices`. The following example sets the maximum receive message size to 64 KB (64 * 1024): +Increase the limit by setting in `Program.cs`. The following example sets the maximum receive message size to 64 KB (64 * 1024) in ASP.NET Core 6.0 or later: + +```csharp +builder.Services.AddServerSideBlazor() + .AddHubOptions(options => options.MaximumReceiveMessageSize = 64 * 1024); +``` + +In `Startup.ConfigureServices` for versions of ASP.NET Core earlier than 6.0: ```csharp services.AddServerSideBlazor() diff --git a/aspnetcore/blazor/includes/state-container.md b/aspnetcore/blazor/includes/state-container.md index 296bb18ce13b..433ef90a3ae1 100644 --- a/aspnetcore/blazor/includes/state-container.md +++ b/aspnetcore/blazor/includes/state-container.md @@ -31,13 +31,19 @@ public class StateContainer } ``` -In `Program.Main` (Blazor WebAssembly): +In `Program.cs` (Blazor WebAssembly): ```csharp builder.Services.AddSingleton(); ``` -In `Startup.ConfigureServices` (Blazor Server): +In `Program.cs` (Blazor Server) in ASP.NET Core 6.0 or later: + +```csharp +builder.Services.AddScoped(); +``` + +In `Startup.ConfigureServices` (Blazor Server) in versions of ASP.NET Core earlier than 6.0: ```csharp services.AddScoped(); diff --git a/aspnetcore/blazor/javascript-interoperability/call-javascript-from-dotnet.md b/aspnetcore/blazor/javascript-interoperability/call-javascript-from-dotnet.md index 08045fd6af9b..4a928624d7d3 100644 --- a/aspnetcore/blazor/javascript-interoperability/call-javascript-from-dotnet.md +++ b/aspnetcore/blazor/javascript-interoperability/call-javascript-from-dotnet.md @@ -412,10 +412,10 @@ In the preceding example, the namespace of the app is `BlazorSample` with shared In Blazor Server apps, JavaScript (JS) interop may fail due to networking errors and should be treated as unreliable. By default, Blazor Server apps use a one minute timeout for JS interop calls. If an app can tolerate a more aggressive timeout, set the timeout using one of the following approaches. -Set a global timeout in the `Startup.ConfigureServices` method of `Startup.cs` with : +Set a global timeout in the `Program.cs` with : ```csharp -services.AddServerSideBlazor( +builder.Services.AddServerSideBlazor( options => options.JSInteropDefaultCallTimeout = {TIMEOUT}); ``` diff --git a/aspnetcore/blazor/project-structure.md b/aspnetcore/blazor/project-structure.md index a871b17cb106..08fb602e2858 100644 --- a/aspnetcore/blazor/project-structure.md +++ b/aspnetcore/blazor/project-structure.md @@ -89,12 +89,10 @@ The Blazor Server template creates the initial files and directory structure for * `appsettings.json` and environmental app settings files: Provide [configuration settings](xref:blazor/fundamentals/configuration) for the app. -* `Program.cs`: The app's entry point that sets up the ASP.NET Core [host](xref:fundamentals/host/generic-host). - -* `Startup.cs`: Contains the app's startup logic. The `Startup` class defines two methods: +* `Program.cs`: The app's entry point that sets up the ASP.NET Core [host](xref:fundamentals/host/generic-host) and contains the app's startup logic, including service registrations and request processing pipeline configuration: - * `ConfigureServices`: Configures the app's [dependency injection (DI)](xref:fundamentals/dependency-injection) services. Services are added by calling , and the `WeatherForecastService` is added to the service container for use by the example `FetchData` component. - * `Configure`: Configures the app's request handling pipeline: + * Specifies the app's [dependency injection (DI)](xref:fundamentals/dependency-injection) services. Services are added by calling , and the `WeatherForecastService` is added to the service container for use by the example `FetchData` component. + * Configures the app's request handling pipeline: * is called to set up an endpoint for the real-time connection with the browser. The connection is created with [SignalR](xref:signalr/introduction), which is a framework for adding real-time web functionality to apps. * [`MapFallbackToPage("/_Host")`](xref:Microsoft.AspNetCore.Builder.RazorPagesEndpointRouteBuilderExtensions.MapFallbackToPage%2A) is called to set up the root page of the app (`Pages/_Host.cshtml`) and enable navigation. diff --git a/aspnetcore/blazor/samples/6.0/BlazorSample_Server/routing/Program.cs b/aspnetcore/blazor/samples/6.0/BlazorSample_Server/routing/Program.cs new file mode 100644 index 000000000000..80ea9be3e81b --- /dev/null +++ b/aspnetcore/blazor/samples/6.0/BlazorSample_Server/routing/Program.cs @@ -0,0 +1,4 @@ +app.UseRouting(); + +app.MapBlazorHub(); +app.MapFallbackToPage("/_Host"); diff --git a/aspnetcore/blazor/samples/6.0/BlazorSample_Server/routing/Startup.cs b/aspnetcore/blazor/samples/6.0/BlazorSample_Server/routing/Startup.cs deleted file mode 100644 index 3627ef4cc3c5..000000000000 --- a/aspnetcore/blazor/samples/6.0/BlazorSample_Server/routing/Startup.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.AspNetCore.Builder; - -public class Startup -{ - public void Configure(IApplicationBuilder app) - { - app.UseRouting(); - - app.UseEndpoints(endpoints => - { - endpoints.MapBlazorHub(); - endpoints.MapFallbackToPage("/_Host"); - }); - } -} diff --git a/aspnetcore/blazor/security/content-security-policy.md b/aspnetcore/blazor/security/content-security-policy.md index 156cb843fb2c..51a87271f8d5 100644 --- a/aspnetcore/blazor/security/content-security-policy.md +++ b/aspnetcore/blazor/security/content-security-policy.md @@ -21,7 +21,7 @@ uid: blazor/security/content-security-policy To apply a CSP to an app, the developer specifies several CSP content security *directives* in one or more `Content-Security-Policy` headers or `` tags. -Policies are evaluated by the browser while a page is loading. The browser inspects the page's sources and determines if they meet the requirements of the content security directives. When policy directives aren't met for a resource, the browser doesn't load the resource. For example, consider a policy that doesn't allow third-party scripts. When a page contains a `