-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[Blazor] Update discovery APIs and automatically configure the endpoints based on the discovered RenderModes #48283
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fce9e66
Update discovery APIs and automatically configure the server endpoint…
javiercn 46399e5
Remove the reference to IRazorComponentApplication
javiercn 1446c70
Remove tests added by mistake
javiercn d4f65b4
Cleanups
javiercn ba6680e
Tests, api cleanups
javiercn a2779c9
Fix multiple lines
javiercn 9950d5a
Cleanups, feedback
javiercn 88ecde6
More cleanups
javiercn c49f2cd
More cleanups
javiercn fd50e8c
Added more tests for capturing the behavior of EndpointDataSource
javiercn eabe351
APIs to set the render mode to common values,
javiercn 37251fa
Update options and tests to match new behavior
javiercn 28e9c61
Fix build
javiercn a6d130c
Cleanups
javiercn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/Components/Endpoints/src/Builder/RazorComponentApplicationAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Components.Discovery; | ||
|
||
namespace Microsoft.AspNetCore.Components.Infrastructure; | ||
|
||
/// <summary> | ||
/// Indicates how to collect the components that are part of a razor components | ||
/// application. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] | ||
public abstract class RazorComponentApplicationAttribute : Attribute, IRazorComponentApplication | ||
{ | ||
/// <summary> | ||
/// Creates a builder that can be used to customize the definition of the application. | ||
/// For example, to add or remove pages, change routes, etc. | ||
/// </summary> | ||
/// <returns> | ||
/// The <see cref="ComponentApplicationBuilder"/> associated with the application definition. | ||
/// </returns> | ||
public abstract ComponentApplicationBuilder GetBuilder(); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Components/Endpoints/src/Builder/RazorComponentDataSourceOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace Microsoft.AspNetCore.Components.Endpoints; | ||
|
||
/// <summary> | ||
/// Options associated with the endpoints defined by the components in the | ||
/// given <see cref="RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents{TRootComponent}(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder)"/> | ||
/// invocation. | ||
/// </summary> | ||
public class RazorComponentDataSourceOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets whether to automatically wire up the necessary endpoints | ||
/// based on the declared render modes of the components that are | ||
/// part of this set of endpoints. | ||
/// </summary> | ||
/// <remarks> | ||
/// The default value is <c>true</c>. | ||
/// </remarks> | ||
public bool UseDeclaredRenderModes { get; set; } = true; | ||
|
||
internal IList<IComponentRenderMode> ConfiguredRenderModes { get; } = new List<IComponentRenderMode>(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 12 additions & 5 deletions
17
src/Components/Endpoints/src/Builder/RazorComponentEndpointDataSourceFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Components.Discovery; | ||
using Microsoft.AspNetCore.Components.Endpoints; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace Microsoft.AspNetCore.Components.Infrastructure; | ||
|
||
internal class RazorComponentEndpointDataSourceFactory | ||
{ | ||
private readonly RazorComponentEndpointFactory _factory; | ||
private readonly IEnumerable<RenderModeEndpointProvider> _providers; | ||
|
||
public RazorComponentEndpointDataSourceFactory(RazorComponentEndpointFactory factory) | ||
public RazorComponentEndpointDataSourceFactory( | ||
RazorComponentEndpointFactory factory, | ||
IEnumerable<RenderModeEndpointProvider> providers) | ||
{ | ||
_factory = factory; | ||
_providers = providers; | ||
} | ||
|
||
public RazorComponentEndpointDataSource<TRootComponent> CreateDataSource<TRootComponent>() | ||
where TRootComponent : IRazorComponentApplication<TRootComponent> | ||
public RazorComponentEndpointDataSource<TRootComponent> CreateDataSource<TRootComponent>(IEndpointRouteBuilder endpoints) | ||
{ | ||
var builder = TRootComponent.GetBuilder(); | ||
return new RazorComponentEndpointDataSource<TRootComponent>(builder, _factory); | ||
var builder = ComponentApplicationBuilder.GetBuilder<TRootComponent>() ?? | ||
DefaultRazorComponentApplication<TRootComponent>.Instance.GetBuilder(); | ||
|
||
return new RazorComponentEndpointDataSource<TRootComponent>(builder, _providers, endpoints.CreateApplicationBuilder(), _factory); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Components/Endpoints/src/Builder/RenderModeEndpointProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace Microsoft.AspNetCore.Components.Endpoints; | ||
|
||
/// <summary> | ||
/// A provider that can register endpoints to support a specific <see cref="IComponentRenderMode"/>. | ||
/// </summary> | ||
public abstract class RenderModeEndpointProvider | ||
{ | ||
/// <summary> | ||
/// Determines whether this <see cref="RenderModeEndpointProvider"/> supports the specified <paramref name="renderMode"/>. | ||
/// </summary> | ||
/// <param name="renderMode">The <see cref="IComponentRenderMode"/>.</param> | ||
/// <returns><c>true</c> if the <see cref="IComponentRenderMode"/> is supported; <c>false</c> otherwise.</returns> | ||
public abstract bool Supports(IComponentRenderMode renderMode); | ||
|
||
/// <summary> | ||
/// Gets the endpoints for the specified <paramref name="renderMode"/>. | ||
/// </summary> | ||
/// <param name="renderMode">The <see cref="IComponentRenderMode"/>.</param> | ||
/// <param name="applicationBuilder">The <see cref="IApplicationBuilder"/> used to configure non endpoint aware endpoints.</param> | ||
/// <returns>The list of endpoints this provider is registering.</returns> | ||
public abstract IEnumerable<RouteEndpointBuilder> GetEndpointBuilders( | ||
IComponentRenderMode renderMode, | ||
IApplicationBuilder applicationBuilder); | ||
|
||
internal static void AddEndpoints( | ||
List<Endpoint> endpoints, | ||
Type rootComponent, | ||
IEnumerable<RouteEndpointBuilder> renderModeEndpoints, | ||
IComponentRenderMode renderMode, | ||
List<Action<EndpointBuilder>> conventions, | ||
List<Action<EndpointBuilder>> finallyConventions) | ||
{ | ||
foreach (var builder in renderModeEndpoints) | ||
{ | ||
builder.Metadata.Add(new RootComponentMetadata(rootComponent)); | ||
builder.Metadata.Add(renderMode); | ||
|
||
foreach (var convention in conventions) | ||
{ | ||
convention(builder); | ||
} | ||
|
||
foreach (var finallyConvention in finallyConventions) | ||
{ | ||
finallyConvention(builder); | ||
} | ||
|
||
endpoints.Add(builder.Build()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.