-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Blazor] Manual reflection based page discovery #49757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Blazor] Manual reflection based page discovery #49757
Conversation
159a617
to
264804c
Compare
0f932bd
to
fbd01d0
Compare
54723f6
to
637d7ef
Compare
/// <remarks> | ||
/// The provided assemblies will be scanned for pages that will be mapped as endpoints. | ||
/// </remarks> | ||
public static RazorComponentEndpointConventionBuilder AddAssemblies( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we settle on AddAssemblies
? That's my preference and what I thought we agreed on, but you were sharing your screen, and your most recent edit of the proposal #49756 showed AddAdditionalAssemblies
. I can update #49756 (comment). I just want to make sure this is intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing I like about AddAdditionalAssemblies
is that the name implies that not all assemblies have to be added here, just the "additional" ones, i.e., external assemblies that don't get scanned by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand that implication at all. We don't call AddSingleton
AddAdditionalSingleton
just because there are some default singleton services like IServiceProvider
.
That said, I said basically this during API review, and I think the consensus was that we should add Additional
to the method name to make it super clear that the main assembly is included by default.
src/Components/Endpoints/src/Builder/RazorComponentEndpointConventionBuilder.cs
Outdated
Show resolved
Hide resolved
/// <returns>The <see cref="RazorComponentEndpointConventionBuilder"/>.</returns> | ||
public static RazorComponentEndpointConventionBuilder AddWebAssemblyRenderMode( | ||
this RazorComponentEndpointConventionBuilder builder, | ||
WebAssemblyComponentsEndpointOptions? options = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another one where I personally prefer WebAssemblyComponentsEndpointOptions
, but we approved WebAssemblyComponentsEndpointsOptions
in the API approval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed - I've just changed it to WebAssemblyComponentsEndpointOptions
src/Components/Endpoints/src/DependencyInjection/RazorComponentOptions.cs
Outdated
Show resolved
Hide resolved
Do we expect the |
I've just addressed some of the PR feedback about API changes. This is ready to be reviewed again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to approve to unblock, but we should update the API proposal to match what we're doing, and have a discussion about the major changes to AddWebAssemblyRenderMode.
/// Adds the given <paramref name="renderMode"/> to the list of configured render modes if not present. | ||
/// </summary> | ||
/// <param name="renderMode">The <see cref="IComponentRenderMode"/> to add.</param> | ||
public void AddRenderMode(IComponentRenderMode renderMode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void AddRenderMode(IComponentRenderMode renderMode) | |
public RazorComponentsEndpointConventionBuilder AddRenderMode(IComponentRenderMode renderMode) |
Wasn't there supposed to be AddWebAssemblyRenderMode()
directly on the RazorComponentsEndpointConventionBuilder
according to the approved API proposal at #49754?
I don't think we approved any IComponentRenderMode
APIs other than RenderModeEndpointProvider
which we tried to hide in an Infrastructure namespace. I don't think RenderMode
or the IComponentRenderMode
interface itself was ever proposed as API either.
I see that this is being called by an AddWebAssemblyRenderMode
extension method in WebAssemblyRazorComponentsEndpointConventionBuilderExtensions
. I'm assuming this was done for layering reasons so we could flow options via the call to AddWebAssemblyRenderMode(WebAssemblyComponentsEndpointOptions)
.
It's really odd to use different patterns for adding server and webassembly render modes. If we're going to do an extension method for one, we should do it for both. It's also a bit unusual to take an WebAssemblyComponentsEndpointOptions
directly instead of an Action<WebAssemblyComponentsEndpointOptions>
, but maybe it's okay since we're not really doing the options pattern for endpoint config. Regardless, it's something that should be discussed in API review.
src/Components/WebAssembly/Server/src/Builder/WebAssemblyRenderModeWithOptions.cs
Outdated
Show resolved
Hide resolved
src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs
Outdated
Show resolved
Hide resolved
.AddWebAssemblyRenderMode(); | ||
.AddWebAssemblyRenderMode(new WebAssemblyComponentsEndpointOptions | ||
{ | ||
PathPrefix = "/WasmMinimal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddWebAssemblyComponents
is the much more natural place to configure options since it follows the options pattern and aligns nicely with AddServerComponents
.
If we're going to do this last-minute non-API-approved change, shouldn't we at least test what happens if you need per-MapRazorComponents
WebAssmblyComponentsEndpointOptions.PathPrefix
configuration? And verify everything works if you call MapRazorComponents
multiple times with different path prefixes? This is the kind of thing that often doesn't work if you don't test it. I had to do extra work to make MapIdentityApi<TUser>
work if you called it with multiple different TUser
types in one application that I would have never found without testing.
If this is something that is so difficult and unusual that we cannot even test it in time, we're better off going with the simpler global option we had before. If we need per-MapRazorComponents
of this in the future, we could always add a global override that works exactly like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested this locally and it works. IMO, making this an option on the endpoint is ideal because hosting multiple WebAssembly apps is something we already support and document, and ideally we'd want an equivalent pattern with these new APIs.
I can see that there's still some deviation from the original API proposal with this PR, so I'm going to update the API review issue(s) to match these changes and we can make a final decision on Monday.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad it works. I'm fine with keeping it. We should probably make AddServerRenderMode
an extension method as well for consistency. But we can merge this as-is for now and make any final adjustments after we API review it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And can we add an automated test for this too then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And can we add an automated test for this too then?
For sure. Is it fine if we do that in a follow-up? It's actually a bit involved, and I probably won't be able to finish by EOD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine with me.
/// <returns>An <see cref="IRazorComponentsBuilder"/> that can be used to further configure the Razor component services.</returns> | ||
[RequiresUnreferencedCode("Razor Components does not currently support trimming or native AOT.", Url = "https://aka.ms/aspnet/trimming")] | ||
public static IRazorComponentsBuilder AddRazorComponents(this IServiceCollection services) | ||
[RequiresUnreferencedCode("Razor Components does not currently support trimming or native AOT.", Url = "https://aka.ms/aspnet/nativeaot")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this URL changed? I believe the intention in #49377 was for this URL to be https://aka.ms/aspnet/trimming.
AddWebAssemblyRenderMode
not in the DI container #49753