Skip to content

Commit 1f7f738

Browse files
API review followups (#50181)
* RazorComponentResult: change namespace, make executor internal, merge test classes * RazorComponentResult: Nullability and trim annotations * RazorComponentResult: IStatusCodeHttpResult and IContentTypeHttpResult * Cleanup * Further clean up annotations * Remove HtmlRootComponent.ComponentId as per API review * Rename SupplyParameterFromFormAttribute.Handler to FormName * API review: seal * Clarify RenderModeAttribute inheritance. Fixes #49848 * Rename valueFactory -> initialValueFactory * Remove unnecessary sequence params * Make [StreamRendering] default to true
1 parent 0e5ea7e commit 1f7f738

File tree

55 files changed

+623
-661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+623
-661
lines changed

src/Components/Components/src/CascadingValueServiceCollectionExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public static class CascadingValueServiceCollectionExtensions
1717
/// </summary>
1818
/// <typeparam name="TValue">The value type.</typeparam>
1919
/// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
20-
/// <param name="valueFactory">A callback that supplies a fixed value within each service provider scope.</param>
20+
/// <param name="initialValueFactory">A callback that supplies a fixed value within each service provider scope.</param>
2121
/// <returns>The <see cref="IServiceCollection"/>.</returns>
2222
public static IServiceCollection AddCascadingValue<TValue>(
23-
this IServiceCollection serviceCollection, Func<IServiceProvider, TValue> valueFactory)
24-
=> serviceCollection.AddScoped<ICascadingValueSupplier>(sp => new CascadingValueSource<TValue>(() => valueFactory(sp), isFixed: true));
23+
this IServiceCollection serviceCollection, Func<IServiceProvider, TValue> initialValueFactory)
24+
=> serviceCollection.AddScoped<ICascadingValueSupplier>(sp => new CascadingValueSource<TValue>(() => initialValueFactory(sp), isFixed: true));
2525

2626
/// <summary>
2727
/// Adds a cascading value to the <paramref name="serviceCollection"/>. This is equivalent to having
@@ -30,11 +30,11 @@ public static IServiceCollection AddCascadingValue<TValue>(
3030
/// <typeparam name="TValue">The value type.</typeparam>
3131
/// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
3232
/// <param name="name">A name for the cascading value. If set, <see cref="CascadingParameterAttribute"/> can be configured to match based on this name.</param>
33-
/// <param name="valueFactory">A callback that supplies a fixed value within each service provider scope.</param>
33+
/// <param name="initialValueFactory">A callback that supplies a fixed value within each service provider scope.</param>
3434
/// <returns>The <see cref="IServiceCollection"/>.</returns>
3535
public static IServiceCollection AddCascadingValue<TValue>(
36-
this IServiceCollection serviceCollection, string name, Func<IServiceProvider, TValue> valueFactory)
37-
=> serviceCollection.AddScoped<ICascadingValueSupplier>(sp => new CascadingValueSource<TValue>(name, () => valueFactory(sp), isFixed: true));
36+
this IServiceCollection serviceCollection, string name, Func<IServiceProvider, TValue> initialValueFactory)
37+
=> serviceCollection.AddScoped<ICascadingValueSupplier>(sp => new CascadingValueSource<TValue>(name, () => initialValueFactory(sp), isFixed: true));
3838

3939
/// <summary>
4040
/// Adds a cascading value to the <paramref name="serviceCollection"/>. This is equivalent to having

src/Components/Components/src/CascadingValueSource.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ public CascadingValueSource(string name, TValue value, bool isFixed) : this(valu
4848
/// <summary>
4949
/// Constructs an instance of <see cref="CascadingValueSource{TValue}"/>.
5050
/// </summary>
51-
/// <param name="valueFactory">A callback that produces the initial value when first required.</param>
51+
/// <param name="initialValueFactory">A callback that produces the initial value when first required.</param>
5252
/// <param name="isFixed">A flag to indicate whether the value is fixed. If false, all receipients will subscribe for update notifications, which you can issue by calling <see cref="NotifyChangedAsync()"/>. These subscriptions come at a performance cost, so if the value will not change, set <paramref name="isFixed"/> to true.</param>
53-
public CascadingValueSource(Func<TValue> valueFactory, bool isFixed) : this(isFixed)
53+
public CascadingValueSource(Func<TValue> initialValueFactory, bool isFixed) : this(isFixed)
5454
{
55-
_initialValueFactory = valueFactory;
55+
_initialValueFactory = initialValueFactory;
5656
}
5757

5858
/// <summary>
5959
/// Constructs an instance of <see cref="CascadingValueSource{TValue}"/>.
6060
/// </summary>
6161
/// <param name="name">A name for the cascading value. If set, <see cref="CascadingParameterAttribute"/> can be configured to match based on this name.</param>
62-
/// <param name="valueFactory">A callback that produces the initial value when first required.</param>
62+
/// <param name="initialValueFactory">A callback that produces the initial value when first required.</param>
6363
/// <param name="isFixed">A flag to indicate whether the value is fixed. If false, all receipients will subscribe for update notifications, which you can issue by calling <see cref="NotifyChangedAsync()"/>. These subscriptions come at a performance cost, so if the value will not change, set <paramref name="isFixed"/> to true.</param>
64-
public CascadingValueSource(string name, Func<TValue> valueFactory, bool isFixed) : this(valueFactory, isFixed)
64+
public CascadingValueSource(string name, Func<TValue> initialValueFactory, bool isFixed) : this(initialValueFactory, isFixed)
6565
{
6666
ArgumentNullException.ThrowIfNull(name);
6767
_name = name;

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Microsoft.AspNetCore.Components.CascadingParameterInfo.CascadingParameterInfo()
88
Microsoft.AspNetCore.Components.CascadingParameterInfo.PropertyName.get -> string!
99
Microsoft.AspNetCore.Components.CascadingParameterInfo.PropertyType.get -> System.Type!
1010
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>
11-
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(string! name, System.Func<TValue>! valueFactory, bool isFixed) -> void
11+
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(string! name, System.Func<TValue>! initialValueFactory, bool isFixed) -> void
1212
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(string! name, TValue value, bool isFixed) -> void
13-
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(System.Func<TValue>! valueFactory, bool isFixed) -> void
13+
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(System.Func<TValue>! initialValueFactory, bool isFixed) -> void
1414
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(TValue value, bool isFixed) -> void
1515
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.NotifyChangedAsync() -> System.Threading.Tasks.Task!
1616
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.NotifyChangedAsync(TValue newValue) -> System.Threading.Tasks.Task!
@@ -24,10 +24,10 @@ Microsoft.AspNetCore.Components.RenderHandle.DispatchExceptionAsync(System.Excep
2424
Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri(string? relativeUri) -> System.Uri!
2525
Microsoft.AspNetCore.Components.Rendering.ComponentState.LogicalParentComponentState.get -> Microsoft.AspNetCore.Components.Rendering.ComponentState?
2626
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentParameter(int sequence, string! name, Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
27-
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentRenderMode(int sequence, Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
2827
*REMOVED*Microsoft.AspNetCore.Components.RouteData.RouteData(System.Type! pageType, System.Collections.Generic.IReadOnlyDictionary<string!, object!>! routeValues) -> void
2928
*REMOVED*Microsoft.AspNetCore.Components.RouteData.RouteValues.get -> System.Collections.Generic.IReadOnlyDictionary<string!, object!>!
30-
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddNamedEvent(int sequence, string! eventType, string! assignedName) -> void
29+
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentRenderMode(Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
30+
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddNamedEvent(string! eventType, string! assignedName) -> void
3131
Microsoft.AspNetCore.Components.RenderTree.ComponentFrameFlags
3232
Microsoft.AspNetCore.Components.RenderTree.ComponentFrameFlags.HasCallerSpecifiedRenderMode = 1 -> Microsoft.AspNetCore.Components.RenderTree.ComponentFrameFlags
3333
Microsoft.AspNetCore.Components.RenderTree.NamedEventChange
@@ -80,17 +80,17 @@ Microsoft.AspNetCore.Components.Sections.SectionOutlet.SectionOutlet() -> void
8080
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentParameter(int sequence, string! name, object? value) -> void
8181
Microsoft.AspNetCore.Components.StreamRenderingAttribute
8282
Microsoft.AspNetCore.Components.StreamRenderingAttribute.Enabled.get -> bool
83-
Microsoft.AspNetCore.Components.StreamRenderingAttribute.StreamRenderingAttribute(bool enabled) -> void
83+
Microsoft.AspNetCore.Components.StreamRenderingAttribute.StreamRenderingAttribute(bool enabled = true) -> void
8484
Microsoft.AspNetCore.Components.SupplyParameterFromQueryProviderServiceCollectionExtensions
8585
Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions
8686
override Microsoft.AspNetCore.Components.EventCallback.GetHashCode() -> int
8787
override Microsoft.AspNetCore.Components.EventCallback.Equals(object? obj) -> bool
8888
override Microsoft.AspNetCore.Components.EventCallback<TValue>.GetHashCode() -> int
8989
override Microsoft.AspNetCore.Components.EventCallback<TValue>.Equals(object? obj) -> bool
9090
static Microsoft.AspNetCore.Components.SupplyParameterFromQueryProviderServiceCollectionExtensions.AddSupplyValueFromQueryProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
91-
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, string! name, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
91+
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, string! name, System.Func<System.IServiceProvider!, TValue>! initialValueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
9292
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, Microsoft.AspNetCore.Components.CascadingValueSource<TValue>!>! sourceFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
93-
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
93+
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, TValue>! initialValueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
9494
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.TryAddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, string! name, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> void
9595
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.TryAddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, Microsoft.AspNetCore.Components.CascadingValueSource<TValue>!>! sourceFactory) -> void
9696
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.TryAddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> void

src/Components/Components/src/RenderModeAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Components;
1010
/// be implemented to work across all render modes. Component authors should only specify
1111
/// a fixed rendering mode when the component is incapable of running in other modes.
1212
/// </summary>
13-
[AttributeUsage(AttributeTargets.Class)]
13+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
1414
public abstract class RenderModeAttribute : Attribute
1515
{
1616
/// <summary>

src/Components/Components/src/RenderTree/RenderTreeFrameArrayBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void AppendRegion(int sequence)
135135
};
136136
}
137137

138-
public void AppendComponentRenderMode(int sequence, IComponentRenderMode renderMode)
138+
public void AppendComponentRenderMode(IComponentRenderMode renderMode)
139139
{
140140
if (_itemsInUse == _items.Length)
141141
{
@@ -144,13 +144,13 @@ public void AppendComponentRenderMode(int sequence, IComponentRenderMode renderM
144144

145145
_items[_itemsInUse++] = new RenderTreeFrame
146146
{
147-
SequenceField = sequence,
147+
SequenceField = 0, // We're only interested in one of these, so it's not useful to optimize diffing over multiple
148148
FrameTypeField = RenderTreeFrameType.ComponentRenderMode,
149149
ComponentRenderModeField = renderMode,
150150
};
151151
}
152152

153-
public void AppendNamedEvent(int sequence, string eventType, string assignedName)
153+
public void AppendNamedEvent(string eventType, string assignedName)
154154
{
155155
if (_itemsInUse == _items.Length)
156156
{
@@ -159,7 +159,7 @@ public void AppendNamedEvent(int sequence, string eventType, string assignedName
159159

160160
_items[_itemsInUse++] = new RenderTreeFrame
161161
{
162-
SequenceField = sequence,
162+
SequenceField = 0, // We're only interested in one of these per eventType, so it's not useful to optimize diffing over multiple
163163
FrameTypeField = RenderTreeFrameType.NamedEvent,
164164
NamedEventTypeField = eventType,
165165
NamedEventAssignedNameField = assignedName,

src/Components/Components/src/Rendering/RenderTreeBuilder.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed class RenderTreeBuilder : IDisposable
2828
private bool _hasSeenAddMultipleAttributes;
2929
private Dictionary<string, int>? _seenAttributeNames;
3030
private IComponentRenderMode? _pendingComponentCallSiteRenderMode; // TODO: Remove when Razor compiler supports call-site @rendermode
31-
private (int Sequence, string AssignedName)? _pendingNamedSubmitEvent; // TODO: Remove when Razor compiler supports @formname
31+
private string? _pendingNamedSubmitEvent; // TODO: Remove when Razor compiler supports @formname
3232

3333
/// <summary>
3434
/// The reserved parameter name used for supplying child content.
@@ -83,9 +83,9 @@ public void CloseElement()
8383
// TODO: Remove this once Razor supports @formname
8484
private void CompletePendingNamedSubmitEvent()
8585
{
86-
if (_pendingNamedSubmitEvent is { } pendingNamedSubmitEvent)
86+
if (_pendingNamedSubmitEvent is not null)
8787
{
88-
AddNamedEvent(pendingNamedSubmitEvent.Sequence, "onsubmit", pendingNamedSubmitEvent.AssignedName);
88+
AddNamedEvent("onsubmit", _pendingNamedSubmitEvent);
8989
_pendingNamedSubmitEvent = default;
9090
}
9191
}
@@ -241,7 +241,7 @@ public void AddAttribute(int sequence, string name, string? value)
241241
// That should compile directly as a call to AddNamedEvent.
242242
if (string.Equals(name, "@formname", StringComparison.Ordinal) && _lastNonAttributeFrameType == RenderTreeFrameType.Element)
243243
{
244-
_pendingNamedSubmitEvent = (sequence, value!);
244+
_pendingNamedSubmitEvent = value!;
245245
}
246246
else
247247
{
@@ -623,7 +623,7 @@ public void CloseComponent()
623623
{
624624
if (_pendingComponentCallSiteRenderMode is not null)
625625
{
626-
AddComponentRenderMode(0, _pendingComponentCallSiteRenderMode);
626+
AddComponentRenderMode(_pendingComponentCallSiteRenderMode);
627627
_pendingComponentCallSiteRenderMode = null;
628628
}
629629

@@ -681,9 +681,8 @@ public void AddComponentReferenceCapture(int sequence, Action<object> componentR
681681
/// <summary>
682682
/// Adds a frame indicating the render mode on the enclosing component frame.
683683
/// </summary>
684-
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
685684
/// <param name="renderMode">The <see cref="IComponentRenderMode"/>.</param>
686-
public void AddComponentRenderMode(int sequence, IComponentRenderMode renderMode)
685+
public void AddComponentRenderMode(IComponentRenderMode renderMode)
687686
{
688687
ArgumentNullException.ThrowIfNull(renderMode);
689688

@@ -709,17 +708,16 @@ public void AddComponentRenderMode(int sequence, IComponentRenderMode renderMode
709708

710709
parentFrame.ComponentFrameFlagsField |= ComponentFrameFlags.HasCallerSpecifiedRenderMode;
711710

712-
_entries.AppendComponentRenderMode(sequence, renderMode);
711+
_entries.AppendComponentRenderMode(renderMode);
713712
_lastNonAttributeFrameType = RenderTreeFrameType.ComponentRenderMode;
714713
}
715714

716715
/// <summary>
717716
/// Assigns a name to an event in the enclosing element.
718717
/// </summary>
719-
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
720718
/// <param name="eventType">The event type, e.g., 'onsubmit'.</param>
721719
/// <param name="assignedName">The application-assigned name.</param>
722-
public void AddNamedEvent(int sequence, string eventType, string assignedName)
720+
public void AddNamedEvent(string eventType, string assignedName)
723721
{
724722
ArgumentNullException.ThrowIfNull(eventType);
725723
ArgumentException.ThrowIfNullOrEmpty(assignedName);
@@ -733,7 +731,7 @@ public void AddNamedEvent(int sequence, string eventType, string assignedName)
733731
throw new InvalidOperationException($"Named events may only be added as children of frames of type {RenderTreeFrameType.Element}");
734732
}
735733

736-
_entries.AppendNamedEvent(sequence, eventType, assignedName);
734+
_entries.AppendNamedEvent(eventType, assignedName);
737735
_lastNonAttributeFrameType = RenderTreeFrameType.NamedEvent;
738736
}
739737

src/Components/Components/src/StreamRenderingAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class StreamRenderingAttribute : Attribute
1818
/// <summary>
1919
/// Constructs an instance of <see cref="StreamRenderingAttribute"/>
2020
/// </summary>
21-
/// <param name="enabled">A flag to indicate whether this component and its descendants should stream their rendering.</param>
22-
public StreamRenderingAttribute(bool enabled)
21+
/// <param name="enabled">A flag to indicate whether this component and its descendants should stream their rendering. The default value is true.</param>
22+
public StreamRenderingAttribute(bool enabled = true)
2323
{
2424
Enabled = enabled;
2525
}

0 commit comments

Comments
 (0)