Skip to content

Commit 76e9e92

Browse files
authored
Merge pull request #35491 from dotnet/main
2 parents ea3e1ad + 8f790a1 commit 76e9e92

File tree

18 files changed

+2085
-43
lines changed

18 files changed

+2085
-43
lines changed

aspnetcore/blazor/host-and-deploy/webassembly/azure-static-web-apps.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ uid: blazor/host-and-deploy/webassembly/azure-static-web-apps
1414

1515
This article explains how to host and deploy standalone Blazor WebAssembly with [Microsoft Azure Static Web Apps](https://azure.microsoft.com/products/app-service/static).
1616

17+
## App configuration
18+
19+
To ensure that requests for any path return `index.html`, set a navigation fallback route.
20+
21+
Create a file named `staticwebapp.config.json` in the project's root folder with the following content:
22+
23+
```json
24+
{
25+
"navigationFallback": {
26+
"rewrite": "/index.html"
27+
}
28+
}
29+
```
30+
1731
## Deploy from Visual Studio
1832

1933
To deploy from Visual Studio, create a publish profile for Azure Static Web Apps:

aspnetcore/blazor/performance/rendering.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,21 @@ At runtime, components exist in a hierarchy. A root component (the first compone
2222

2323
1. The event is dispatched to the component that rendered the event's handler. After executing the event handler, the component is rerendered.
2424
1. When a component is rerendered, it supplies a new copy of parameter values to each of its child components.
25-
1. After a new set of parameter values is received, each component decides whether to rerender. Components rerender if the parameter values may have changed, for example, if they're mutable objects.
25+
1. After a new set of parameter values is received, Blazor decides whether to rerender the component. Components rerender if [`ShouldRender`](xref:blazor/components/rendering#suppress-ui-refreshing-shouldrender) returns `true`, which is the default behavior unless overridden, and the parameter values may have changed, for example, if they're mutable objects.
2626

2727
The last two steps of the preceding sequence continue recursively down the component hierarchy. In many cases, the entire subtree is rerendered. Events targeting high-level components can cause expensive rerendering because every component below the high-level component must rerender.
2828

2929
To prevent rendering recursion into a particular subtree, use either of the following approaches:
3030

31-
* Ensure that child component parameters are of primitive immutable types, such as `string`, `int`, `bool`, `DateTime`, and other similar types. The built-in logic for detecting changes automatically skips rerendering if the primitive immutable parameter values haven't changed. If you render a child component with `<Customer CustomerId="item.CustomerId" />`, where `CustomerId` is an `int` type, then the `Customer` component isn't rerendered unless `item.CustomerId` changes.
32-
* Override <xref:Microsoft.AspNetCore.Components.ComponentBase.ShouldRender%2A>:
33-
* To accept nonprimitive parameter values, such as complex custom model types, event callbacks, or <xref:Microsoft.AspNetCore.Components.RenderFragment> values.
31+
* Ensure that child component parameters are of specific immutable types&dagger;, such as `string`, `int`, `bool`, and `DateTime`. The built-in logic for detecting changes automatically skips rerendering if the immutable parameter values haven't changed. If you render a child component with `<Customer CustomerId="item.CustomerId" />`, where `CustomerId` is an `int` type, then the `Customer` component isn't rerendered unless `item.CustomerId` changes.
32+
* Override [`ShouldRender`](xref:blazor/components/rendering#suppress-ui-refreshing-shouldrender), returning `false`:
33+
* When parameters are nonprimitive types or unsupported immutable types&dagger;, such as complex custom model types or <xref:Microsoft.AspNetCore.Components.RenderFragment> values, and the parameter values haven't changed,
3434
* If authoring a UI-only component that doesn't change after the initial render, regardless of parameter value changes.
3535

36+
&dagger;For more information, see [the change detection logic in Blazor's reference source (`ChangeDetection.cs`)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/Components/src/ChangeDetection.cs).
37+
38+
[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]
39+
3640
The following airline flight search tool example uses private fields to track the necessary information to detect changes. The previous inbound flight identifier (`prevInboundFlightId`) and previous outbound flight identifier (`prevOutboundFlightId`) track information for the next potential component update. If either of the flight identifiers change when the component's parameters are set in [`OnParametersSet`](xref:blazor/components/lifecycle#after-parameters-are-set-onparameterssetasync), the component is rerendered because `shouldRender` is set to `true`. If `shouldRender` evaluates to `false` after checking the flight identifiers, an expensive rerender is avoided:
3741

3842
```razor

aspnetcore/blazor/performance/webassembly-browser-developer-tools-diagnostics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ Filter | Description
102102
`+EXPR` | Includes expression
103103
`-EXPR` | Excludes expression
104104

105-
In the following example, profiled methods are filtered to the app's namespace, which is represented by the `{APP NAMESPACE}` placeholder:
105+
In the following example, profiled methods are filtered to the app's namespace `SampleApp` and sampling interval is 50ms.
106106

107107
```xml
108-
<WasmProfilers>browser:callspec=N:{APP NAMESPACE};</WasmProfilers>
108+
<WasmProfilers>browser:callspec=N:SampleApp,interval=50</WasmProfilers>
109109
```
110110

111111
## Additional resources

aspnetcore/client-side/libman/samples/LibManSample/LibManSample.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
5-
<TypeScriptToolsVersion>3.0</TypeScriptToolsVersion>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.App" />
109
<!-- <snippet_RestoreOnBuildPackage> -->
11-
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.113" />
10+
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="3.0.71" />
1211
<!-- </snippet_RestoreOnBuildPackage> -->
1312
</ItemGroup>
1413

aspnetcore/client-side/libman/samples/LibManSample/Startup.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
using Microsoft.AspNetCore.Hosting;
77
using Microsoft.AspNetCore.Http;
88
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Hosting;
910

1011
namespace LibManSample
1112
{
1213
public class Startup
1314
{
1415
// This method gets called by the runtime. Use this method to add services to the container.
1516
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
16-
public void ConfigureServices(IServiceCollection services)
17+
public void ConfigureServices()
1718
{
1819
}
1920

2021
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
21-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
22+
public void Configure(IApplicationBuilder app, IHostEnvironment env)
2223
{
2324
if (env.IsDevelopment())
2425
{

aspnetcore/client-side/libman/samples/LibManSample/libman.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"defaultProvider": "cdnjs",
44
"libraries": [
55
{
6-
"library": "jquery@3.3.1",
6+
"library": "jquery@3.7.1",
77
"files": [
88
"jquery.min.js",
99
"jquery.js",
@@ -13,17 +13,8 @@
1313
},
1414
{
1515
"provider": "unpkg",
16-
"library": "bootstrap@4.1.3",
16+
"library": "bootstrap@5.3.6",
1717
"destination": "wwwroot/lib/bootstrap/"
18-
},
19-
{
20-
"provider": "filesystem",
21-
"library": "C:\\temp\\lodash\\",
22-
"files": [
23-
"lodash.js",
24-
"lodash.min.js"
25-
],
26-
"destination": "wwwroot/lib/lodash/"
2718
}
2819
]
29-
}
20+
}

aspnetcore/fundamentals/minimal-apis.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Provides an overview of minimal APIs in ASP.NET Core
55
ms.author: wpickett
66
content_well_notification: AI-contribution
77
monikerRange: '>= aspnetcore-6.0'
8-
ms.date: 02/07/2025
8+
ms.date: 05/19/2025
99
uid: fundamentals/minimal-apis
1010
ai-usage: ai-assisted
1111
---
@@ -16,7 +16,7 @@ ai-usage: ai-assisted
1616

1717
[!INCLUDE[](~/includes/not-latest-version.md)]
1818

19-
:::moniker range=">= aspnetcore-8.0"
19+
:::moniker range=">= aspnetcore-10.0"
2020

2121
This document:
2222

@@ -28,7 +28,7 @@ The minimal APIs consist of:
2828
* [WebApplication and WebApplicationBuilder](xref:fundamentals/minimal-apis/webapplication)
2929
* [Route Handlers](xref:fundamentals/minimal-apis/route-handlers)
3030

31-
[!INCLUDE[](~/fundamentals/minimal-apis/includes/webapplication8.md)]
31+
[!INCLUDE[](~/fundamentals/minimal-apis/includes/webapplication10.md)]
3232

3333
## ASP.NET Core Middleware
3434

@@ -68,7 +68,50 @@ The <xref:System.Delegate> arguments passed to these methods are called "route h
6868

6969
## Parameter binding
7070

71-
[!INCLUDE [](~/fundamentals/minimal-apis/includes/parameter-binding8.md)]
71+
[!INCLUDE [](~/fundamentals/minimal-apis/includes/parameter-binding10.md)]
72+
73+
## Validation support in Minimal APIs
74+
75+
Support for validation in Minimal APIs is now available. This feature allows you to request validation of data sent to your API endpoints. Enabling validation allows the ASP.NET Core runtime to perform any validations defined on the:
76+
77+
* Query
78+
* Header
79+
* Request body
80+
81+
Validations are defined using attributes in the [`DataAnnotations`](xref:System.ComponentModel.DataAnnotations) namespace.
82+
83+
When a parameter to a Minimal API endpoint is a class or record type, validation attributes are automatically applied. For example:
84+
85+
```csharp
86+
public record Product(
87+
[Required] string Name,
88+
[Range(1, 1000)] int Quantity);
89+
```
90+
Developers customize the behavior of the validation system by:
91+
92+
* Creating custom [`[Validation]`](xref:System.ComponentModel.DataAnnotations.ValidationAttribute) attribute implementations.
93+
* Implementing the [`IValidatableObject`](xref:System.ComponentModel.DataAnnotations.IValidatableObject) interface for complex validation logic.
94+
95+
If validation fails, the runtime returns a 400 Bad Request response with details of the validation errors.
96+
97+
### Enable built-in validation support for minimal APIs
98+
99+
Enable the built-in validation support for minimal APIs by calling the `AddValidation` extension method to register the required services in the service container for your application:
100+
101+
```csharp
102+
builder.Services.AddValidation();
103+
```
104+
105+
The implementation automatically discovers types that are defined in minimal API handlers or as base types of types defined in minimal API handlers. An endpoint filter performs validation on these types and is added for each endpoint.
106+
107+
Validation can be disabled for specific endpoints by using the `DisableValidation` extension method, as in the following example:
108+
109+
```csharp
110+
app.MapPost("/products",
111+
([EvenNumber(ErrorMessage = "Product ID must be even")] int productId, [Required] string name)
112+
=> TypedResults.Ok(productId))
113+
.DisableValidation();
114+
```
72115

73116
## Responses
74117

@@ -285,5 +328,7 @@ The following code disables `ValidateScopes` and `ValidateOnBuild` in `Developme
285328

286329
:::moniker-end
287330

331+
[!INCLUDE[](~/fundamentals/minimal-apis/includes/minimal-apis9.md)]
332+
[!INCLUDE[](~/fundamentals/minimal-apis/includes/minimal-apis8.md)]
288333
[!INCLUDE[](~/fundamentals/minimal-apis/includes/minimal-apis7.md)]
289334
[!INCLUDE[](~/fundamentals/minimal-apis/includes/minimal-apis6.md)]

0 commit comments

Comments
 (0)