Skip to content

[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

Merged
merged 15 commits into from
Aug 12, 2023

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Jul 31, 2023

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Jul 31, 2023
@javiercn javiercn force-pushed the javiercn/reflection-based-component-discovery branch from 159a617 to 264804c Compare August 3, 2023 11:56
@javiercn javiercn marked this pull request as ready for review August 3, 2023 12:11
@javiercn javiercn requested review from a team as code owners August 3, 2023 12:11
@javiercn javiercn force-pushed the javiercn/reflection-based-component-discovery branch from 0f932bd to fbd01d0 Compare August 3, 2023 12:57
@javiercn javiercn force-pushed the javiercn/reflection-based-component-discovery branch from 54723f6 to 637d7ef Compare August 3, 2023 17:16
/// <remarks>
/// The provided assemblies will be scanned for pages that will be mapped as endpoints.
/// </remarks>
public static RazorComponentEndpointConventionBuilder AddAssemblies(
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

/// <returns>The <see cref="RazorComponentEndpointConventionBuilder"/>.</returns>
public static RazorComponentEndpointConventionBuilder AddWebAssemblyRenderMode(
this RazorComponentEndpointConventionBuilder builder,
WebAssemblyComponentsEndpointOptions? options = null)
Copy link
Member

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.

Copy link
Member

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

@halter73
Copy link
Member

halter73 commented Aug 3, 2023

Do we expect the RenderModeEndpointProvider namespace change we approved in #49756 in another PR?

@MackinnonBuck MackinnonBuck requested a review from halter73 August 11, 2023 17:27
@MackinnonBuck
Copy link
Member

I've just addressed some of the PR feedback about API changes. This is ready to be reviewed again.

Copy link
Member

@halter73 halter73 left a 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

.AddWebAssemblyRenderMode();
.AddWebAssemblyRenderMode(new WebAssemblyComponentsEndpointOptions
{
PathPrefix = "/WasmMinimal"
Copy link
Member

@halter73 halter73 Aug 11, 2023

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.

Copy link
Member

@MackinnonBuck MackinnonBuck Aug 11, 2023

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.

Copy link
Member

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.

Copy link
Member

@halter73 halter73 Aug 11, 2023

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?

Copy link
Member

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.

Copy link
Member

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.

@MackinnonBuck MackinnonBuck deleted the javiercn/reflection-based-component-discovery branch August 12, 2023 01:42
@ghost ghost added this to the 8.0-rc1 milestone Aug 12, 2023
@danroth27 danroth27 mentioned this pull request Aug 16, 2023
1 task
/// <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")]
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants