-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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] Take cascading parameter attribute type into account when supplying cascading values #48554
Merged
MackinnonBuck
merged 14 commits into
main
from
mbuck/multiple-cascading-parameter-values
Jun 16, 2023
Merged
[Blazor] Take cascading parameter attribute type into account when supplying cascading values #48554
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a9b17cd
Filter cascading parameters by attribute type
MackinnonBuck 4c294a4
Use cascading values for query-supplied parameters
MackinnonBuck 10601dd
Update RouteView.cs
MackinnonBuck fa7d9c5
Update tests
MackinnonBuck 640ec5f
Merged ICascadingValueSupplier{Factory} together
MackinnonBuck 1868b54
Some cleanup
MackinnonBuck 09bae24
Create QueryParameterValueSupplierTest.cs
MackinnonBuck 9b31d05
Merge branch 'main' into mbuck/multiple-cascading-parameter-values
MackinnonBuck 05d5bcb
More PR feedback
MackinnonBuck 4e562dc
Fix test failures
MackinnonBuck 40f9289
Some cleanup
MackinnonBuck 3474f0b
More cleanup
MackinnonBuck 688aaba
Improvements + fix tests
MackinnonBuck 32bc52d
PR feedback
MackinnonBuck 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
This file contains 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 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
69 changes: 69 additions & 0 deletions
69
src/Components/Components/src/Binding/CascadingModelBindingProvider.cs
This file contains 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,69 @@ | ||
// 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.Rendering; | ||
|
||
namespace Microsoft.AspNetCore.Components.Binding; | ||
|
||
/// <summary> | ||
/// Provides values that get supplied to cascading parameters with <see cref="CascadingModelBinder"/>. | ||
/// </summary> | ||
public abstract class CascadingModelBindingProvider | ||
{ | ||
/// <summary> | ||
/// Gets whether values supplied by this instance will not change. | ||
/// </summary> | ||
protected internal abstract bool AreValuesFixed { get; } | ||
|
||
/// <summary> | ||
/// Determines whether this instance can provide values for parameters annotated with the specified attribute type. | ||
/// </summary> | ||
/// <param name="attributeType">The attribute type.</param> | ||
/// <returns><c>true</c> if this instance can provide values for parameters annotated with the specified attribute type, otherwise <c>false</c>.</returns> | ||
protected internal abstract bool SupportsCascadingParameterAttributeType(Type attributeType); | ||
|
||
/// <summary> | ||
/// Determines whether this instance can provide values to parameters with the specified type. | ||
/// </summary> | ||
/// <param name="parameterType">The parameter type.</param> | ||
/// <returns><c>true</c> if this instance can provide values to parameters with the specified type, otherwise <c>false</c>.</returns> | ||
protected internal abstract bool SupportsParameterType(Type parameterType); | ||
|
||
/// <summary> | ||
/// Determines whether this instance can supply a value for the specified parameter. | ||
/// </summary> | ||
/// <param name="bindingContext">The current <see cref="ModelBindingContext"/>.</param> | ||
/// <param name="parameterInfo">The <see cref="CascadingParameterInfo"/> for the component parameter.</param> | ||
/// <returns><c>true</c> if a value can be supplied, otherwise <c>false</c>.</returns> | ||
protected internal abstract bool CanSupplyValue(ModelBindingContext? bindingContext, in CascadingParameterInfo parameterInfo); | ||
|
||
/// <summary> | ||
/// Gets the value for the specified parameter. | ||
/// </summary> | ||
/// <param name="bindingContext">The current <see cref="ModelBindingContext"/>.</param> | ||
/// <param name="parameterInfo">The <see cref="CascadingParameterInfo"/> for the component parameter.</param> | ||
/// <returns>The value to supply to the parameter.</returns> | ||
protected internal abstract object? GetCurrentValue(ModelBindingContext? bindingContext, in CascadingParameterInfo parameterInfo); | ||
|
||
/// <summary> | ||
/// Subscribes to changes in supplied values, if they can change. | ||
/// </summary> | ||
/// <remarks> | ||
/// This method must be implemented if <see cref="AreValuesFixed"/> is <c>false</c>. | ||
/// </remarks> | ||
/// <param name="subscriber">The <see cref="ComponentState"/> for the subscribing component.</param> | ||
protected internal virtual void Subscribe(ComponentState subscriber) | ||
=> throw new InvalidOperationException( | ||
$"'{nameof(CascadingModelBindingProvider)}' instances that have non-fixed values must provide an implementation for '{nameof(Subscribe)}'."); | ||
|
||
/// <summary> | ||
/// Unsubscribes from changes in supplied values, if they can change. | ||
/// </summary> | ||
/// <remarks> | ||
/// This method must be implemented if <see cref="AreValuesFixed"/> is <c>false</c>. | ||
/// </remarks> | ||
/// <param name="subscriber">The <see cref="ComponentState"/> for the unsubscribing component.</param> | ||
protected internal virtual void Unsubscribe(ComponentState subscriber) | ||
=> throw new InvalidOperationException( | ||
$"'{nameof(CascadingModelBindingProvider)}' instances that have non-fixed values must provide an implementation for '{nameof(Unsubscribe)}'."); | ||
} |
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.
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.
Later on, rather than this being a general DI service with a public API, we might change this into a Renderer API so it's not publicly visible or extensible (except for people implementing a renderer). It potentially leads to a whole bunch of simplifications and reductions in API surface. This is something we discussed before, but I think you're right not to add it to this PR.
I'm totally happy with this PR proceeding as-is, since right now this works and we have other things to focus on for preview 6. But just wanted to raise this so it doesn't seem surprising if I try to move around a bunch of this machinery and possible constrain how much we have to support in preview 7. If you have any concerns about that please let me know!