Repository navigation
Conversation
c68b966 to
d9a8361
Compare
d9a8361 to
27ac444
Compare
27ac444 to
617eaa6
Compare
617eaa6 to
58a0cfe
Compare
Discover framework-owned component assemblies and merge their owner descriptors with application metadata. Add generic factory imports and generated UnsafeAccessors for Components, Web, Forms, and Endpoints. Co-authored-by: Copilot App <[email protected]>
Cover core provider imports, explicit closed generic roots, owner factory selection, and provider-aware generator diagnostics while retaining application descriptor isolation. Co-authored-by: Copilot App <[email protected]>
Add owner descriptors for Authorization, QuickGrid, Media, and WebAssembly Authentication, including constrained generic factories, private injection bridges, and required construction paths. Co-authored-by: Copilot App <[email protected]>
Exercise the complete built-in component descriptor matrix, including constrained QuickGrid factories, private injectable bridges, Media construction, and remote authentication component families. Framework JS callback coverage remains in its lower stack layer. Co-authored-by: Copilot App <[email protected]>
Reference optional framework packages beside their owner providers and root representative closed generic components for Forms, virtualization, QuickGrid, and remote authentication in the existing JIT feature harness. Co-authored-by: Copilot App <[email protected]>
58a0cfe to
7a7e46c
Compare
There was a problem hiding this comment.
Pull request overview
This PR extends the Razor Components metadata generator to compose application-generated component descriptors with framework-owned “built-in” descriptor providers/factories (for Native AOT scenarios), and adds framework-side descriptor providers across Components, Web, Forms, Endpoints, Authorization, QuickGrid, Media, and WebAssembly Authentication.
Changes:
- Adds framework-owned
Microsoft.AspNetCore.Components.Infrastructure.BuiltInComponentDescriptorsproviders (and generic descriptor factories) across multiple framework assemblies. - Updates the generator model and emitter to import referenced provider assemblies/factories and merge them into the generated metadata context output (via
UnsafeAccessorbridges). - Expands generator test coverage and test infrastructure references to validate provider selection, factory emission, and descriptor correctness.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Components/WebAssembly/WebAssembly.Authentication/src/Infrastructure/BuiltInComponentDescriptors.cs | Adds WebAssembly Authentication built-in descriptors and RemoteAuthenticatorViewCore factory/injection accessors. |
| src/Components/Web/src/Metadata/BuiltInComponentDescriptors.cs | Adds Web built-in component descriptors and generic factories (e.g., Input*, ValidationMessage, Virtualize) plus accessors. |
| src/Components/test/testassets/BlazorAotFeatures/BlazorServerAotSample/SampleMetadata.cs | Roots representative closed generic component types via [ComponentTypeInfo]. |
| src/Components/test/testassets/BlazorAotFeatures/BlazorServerAotSample/BlazorServerAotSample.csproj | References additional optional framework assemblies to validate provider composition. |
| src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Infrastructure/BuiltInComponentDescriptors.cs | Adds QuickGrid built-in descriptors and factories, including Virtualize tuple factory bridging. |
| src/Components/Media/src/BuiltInComponentDescriptors.cs | Adds Media built-in descriptors with required construction patterns and injectable bridges. |
| src/Components/Forms/src/Infrastructure/BuiltInComponentDescriptors.cs | Adds Forms built-in descriptors for DataAnnotationsValidator with accessors. |
| src/Components/Endpoints/test/Microsoft.AspNetCore.Components.Endpoints.Generators.Tests/RazorComponentsMetadataGeneratorTestBase.cs | Updates test harness helpers and framework reference loading for new provider assemblies. |
| src/Components/Endpoints/test/Microsoft.AspNetCore.Components.Endpoints.Generators.Tests/RazorComponentsMetadataGeneratorSerializationTests.cs | Adjusts serialization tests to filter to referenced-assembly descriptors. |
| src/Components/Endpoints/test/Microsoft.AspNetCore.Components.Endpoints.Generators.Tests/RazorComponentsMetadataGeneratorDiagnosticTests.cs | Updates diagnostics assertions to match new generated-source split and filtering. |
| src/Components/Endpoints/test/Microsoft.AspNetCore.Components.Endpoints.Generators.Tests/RazorComponentsMetadataGeneratorComponentTests.cs | Adds tests for explicit closed generics and built-in factory emission; updates existing assertions. |
| src/Components/Endpoints/test/Microsoft.AspNetCore.Components.Endpoints.Generators.Tests/RazorComponentsMetadataGeneratorBuiltInDescriptorTests.cs | Adds comprehensive provider/factory/descriptor matrix tests for built-in descriptors across assemblies. |
| src/Components/Endpoints/test/Microsoft.AspNetCore.Components.Endpoints.Generators.Tests/Microsoft.AspNetCore.Components.Endpoints.Generators.Tests.csproj | Adds references required for the expanded built-in descriptor/provider test matrix. |
| src/Components/Endpoints/src/RazorComponentEndpointHost.cs | Switches LayoutAttribute lookup from reflection to resolver-provided metadata (AOT-friendly). |
| src/Components/Endpoints/src/Infrastructure/BuiltInComponentDescriptors.cs | Adds Endpoints built-in descriptors for SSR boundary and endpoint-hosting components plus accessors. |
| src/Components/Endpoints/gen/RazorComponentsMetadataGenerator.cs | Adds provider inventory, post-init [ComponentTypeInfo] attribute emission, and composition inputs to the model. |
| src/Components/Endpoints/gen/RazorComponentsMetadataGenerator.Components.cs | Adds implicit/explicit built-in factory discovery and adjusts component collection behavior. |
| src/Components/Endpoints/gen/Models/MetadataContextModel.cs | Extends incremental model with built-in provider assemblies and factory models. |
| src/Components/Endpoints/gen/Emitters/RazorComponentsMetadataGenerator.Emitter.cs | Emits built-in provider accessors and factory calls into the generated component descriptor store. |
| src/Components/Components/src/Infrastructure/BuiltInComponentDescriptors.cs | Adds Components built-in descriptors (e.g., Router, SectionOutlet renderer) and owning-component factory. |
| src/Components/Authorization/src/Infrastructure/BuiltInComponentDescriptors.cs | Adds Authorization built-in descriptors, including private-core construction and hidden member accessors. |
| src/Components/Authorization/src/AuthorizeRouteView.Descriptors.cs | Adds internal helpers to construct/access the private AuthorizeRouteView core type for descriptors. |
| src/Components/Authorization/src/AuthorizeRouteView.cs | Makes AuthorizeRouteView partial to host descriptor helper members. |
Suppressed comments (1)
src/Components/Endpoints/gen/RazorComponentsMetadataGenerator.cs:77
- The generator only collects
ClassDeclarationSyntaxcandidates and castsctx.Nodeaccordingly. This means a metadata context declared as arecord(i.e.,record class ... : RazorComponentsMetadataContext) will never be discovered, and none of its metadata (including[ComponentTypeInfo]) will be generated. Since the model/emission already trackscontextType.IsRecord/TypeKeyword, it looks like record contexts are intended to be supported—consider broadening the syntax filter/transform to includeRecordDeclarationSyntax(orTypeDeclarationSyntax) and updating the downstream plumbing accordingly.
var candidates = context.SyntaxProvider
.CreateSyntaxProvider(
predicate: static (node, _) => IsCandidateContextDeclaration(node),
transform: static (ctx, _) => (ClassDeclarationSyntax)ctx.Node)
.Collect();
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| foreach (var syntaxReference in contextType.DeclaringSyntaxReferences) | ||
| { | ||
| if (syntaxReference.GetSyntax(cancellationToken) is not ClassDeclarationSyntax declaration) | ||
| { | ||
| continue; | ||
| } |
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
Overview
This is layer 5 of 6 for the Aspire Dashboard Native AOT feature, stacked on #68299. Across five commits and 23 files, it teaches the Razor components metadata generator to import component descriptions from the framework assemblies that own those components, then adds providers for Components, Web, Forms, Endpoints, Authorization, QuickGrid, Media, and WebAssembly Authentication. The governing constraint is that application metadata and framework-owner metadata must compose without reflection, while optional assemblies contribute nothing unless the application actually references them; strict reflection switches and Native AOT execution remain in layer 6. The provider tests use the upstream shared MSTest/MTP Components.Testing harness from #67083 and #68289; this PR adds no duplicate testing infrastructure or xUnit dependency.
Design
There is no new public API. The generator emits an internal, compile-time-only attribute that lets the feature application name closed generic roots which cannot be inferred from an open generic definition:
Each owner assembly implements the same internal convention: a type named
Microsoft.AspNetCore.Components.Infrastructure.BuiltInComponentDescriptorsexposesGetDescriptors()for fixed components and named generic factory methods for closed families. The application generator deliberately does not duplicate framework internals: owner providers can access private members, required constructors, and internal helper component graphs safely, while the generator carries only the data required to bind to those factories.This owner-provider design was chosen over application-side reflection or re-describing framework private state. It also preserves package isolation: the known provider list is filtered against the host compilation's referenced assemblies, so Authorization, QuickGrid, Media, and WebAssembly Authentication metadata is imported only when those packages are present. Framework JS callback providers are unchanged and remain owned by the earlier JSInterop layer.
Implementation
The generator starts from the metadata context a consumer already registers. It computes application descriptors once, discovers referenced owner providers, collects implicit and explicitly rooted generic factories, and merges those inputs into the context model:
Emission preserves the lower layer's application descriptors and spreads owner descriptors after them. Both fixed providers and generic factories are linked with generated
UnsafeAccessordeclarations, so the runtime receives ordinary descriptor arrays with no assembly scanning,MakeGenericType, or reflective member access:A fixed owner inventory is represented by Components'
Router: the provider owns activation, every parameter, and injections whose setters are private. Web, Forms, and Endpoints use the same pattern for their non-generic inventories.The remaining provider behaviors form four equivalence classes; one representative and each delta are shown here:
ValidationMessage<T>,Virtualize<T>,OwningComponentBase, QuickGrid families, andRemoteAuthenticatorViewCore<TState>preserve concrete arguments, constraints, and trimming annotations. QuickGrid additionally contributes the internal cascading context and tuple-shaped virtualization helper needed byQuickGrid<T>:AuthorizeView,AuthorizeRouteView,CascadingAuthenticationState, and the private nestedAuthorizeRouteViewCore; owner-side helpers construct the private core whileUnsafeAccessorbridges its inherited private parameters and services. QuickGrid and WebAssembly Authentication use the same bridge pattern for private injections.Image,Video, andFileDownloadcannot use a plain parameterless factory becauseSourceis required. Their owner provider deliberately constructsnew Image { Source = null! }(and peers) before normal parameter assignment and supplies the private JS runtime/logger injections.RemoteAuthenticatorViewCore<TAuthenticationState>preserveswhere TAuthenticationState : RemoteAuthenticationStateplus theJsonSerializedDAM requirement, and closes all five service types over the same authentication-state type.The feature application roots representative closed instances beside their optional assembly references, covering generic Forms inputs, virtualization, application generics, QuickGrid's grid/column/notifier graph, and remote authentication:
Outcome
src/Components/Testing.Validation: the complete built-in descriptor generator matrix passed 113/113 tests. Fast affected suites across Components, Web, Forms, Endpoints, Authorization, QuickGrid, Media, and WebAssembly Authentication passed 2,784 tests with 8 existing skips. The upstream feature harness built cleanly and its focused JIT smoke passed 3/3 tests. Native AOT execution and strict reflection-disabled validation are intentionally deferred to layer 6.