Skip to content

[Blazor] Implement API review feedback: rename pause/resume methods and PersistentState attribute #62549

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 10 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ BenchmarkDotNet.Artifacts/
src/SignalR/clients/**/dist/
modules/
.ionide/
TestResults/

# File extensions
*.aps
Expand All @@ -33,6 +34,7 @@ modules/
*.suo
*.svclog
*.tlog
*.trx
*.user
*.userprefs
*.vspx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public PropertiesAccessor([DynamicallyAccessedMembers(LinkerFlags.Component)] Ty
var keys = new List<(string, Type)>();
foreach (var propertyInfo in GetCandidateBindableProperties(targetType))
{
SupplyParameterFromPersistentComponentStateAttribute? parameterAttribute = null;
PersistentStateAttribute? parameterAttribute = null;
foreach (var attribute in propertyInfo.GetCustomAttributes())
{
if (attribute is SupplyParameterFromPersistentComponentStateAttribute persistentStateAttribute)
if (attribute is PersistentStateAttribute persistentStateAttribute)
{
parameterAttribute = persistentStateAttribute;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace Microsoft.AspNetCore.Components;
/// previous render.
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class SupplyParameterFromPersistentComponentStateAttribute : CascadingParameterAttributeBase
public sealed class PersistentStateAttribute : CascadingParameterAttributeBase
{
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// 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;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Components.Infrastructure;

/// <summary>
/// Enables component parameters to be supplied from <see cref="PersistentComponentState"/> with <see cref="SupplyParameterFromPersistentComponentStateAttribute"/>.
/// Enables component parameters to be supplied from <see cref="PersistentComponentState"/> with <see cref="PersistentStateAttribute"/>.
/// </summary>
public static class SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions
public static class PersistentStateProviderServiceCollectionExtensions
{
/// <summary>
/// Enables component parameters to be supplied from <see cref="PersistentComponentState"/> with <see cref="SupplyParameterFromPersistentComponentStateAttribute"/>..
/// Enables component parameters to be supplied from <see cref="PersistentComponentState"/> with <see cref="PersistentStateAttribute"/>.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddSupplyValueFromPersistentComponentStateProvider(this IServiceCollection services)
{
services.TryAddEnumerable(ServiceDescriptor.Scoped<ICascadingValueSupplier, SupplyParameterFromPersistentComponentStateValueProvider>());
services.TryAddEnumerable(ServiceDescriptor.Scoped<ICascadingValueSupplier, PersistentStateValueProvider>());
return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Internal;

namespace Microsoft.AspNetCore.Components;
namespace Microsoft.AspNetCore.Components.Infrastructure;

internal sealed class SupplyParameterFromPersistentComponentStateValueProvider(PersistentComponentState state) : ICascadingValueSupplier
internal sealed class PersistentStateValueProvider(PersistentComponentState state) : ICascadingValueSupplier
{
private static readonly ConcurrentDictionary<(string, string, string), byte[]> _keyCache = new();
private static readonly ConcurrentDictionary<(Type, string), PropertyGetter> _propertyGetterCache = new();
Expand All @@ -27,7 +27,7 @@ internal sealed class SupplyParameterFromPersistentComponentStateValueProvider(P
internal Dictionary<ComponentState, PersistingComponentStateSubscription> Subscriptions => _subscriptions;

public bool CanSupplyValue(in CascadingParameterInfo parameterInfo)
=> parameterInfo.Attribute is SupplyParameterFromPersistentComponentStateAttribute;
=> parameterInfo.Attribute is PersistentStateAttribute;

[UnconditionalSuppressMessage(
"ReflectionAnalysis",
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Components/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Microsoft.AspNetCore.Components.Routing.NotFoundEventArgs.Path.get -> string!
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.ComponentStatePersistenceManager(Microsoft.Extensions.Logging.ILogger<Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager!>! logger, System.IServiceProvider! serviceProvider) -> void
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.SetPlatformRenderMode(Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions
Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateAttribute
Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateAttribute.SupplyParameterFromPersistentComponentStateAttribute() -> void
Microsoft.Extensions.DependencyInjection.SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions
Microsoft.AspNetCore.Components.PersistentStateAttribute
Microsoft.AspNetCore.Components.PersistentStateAttribute.PersistentStateAttribute() -> void
Microsoft.AspNetCore.Components.Infrastructure.PersistentStateProviderServiceCollectionExtensions
static Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions.AddPersistentServiceRegistration<TService>(Microsoft.Extensions.DependencyInjection.IServiceCollection! services, Microsoft.AspNetCore.Components.IComponentRenderMode! componentRenderMode) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.AspNetCore.Components.Infrastructure.ComponentsMetricsServiceCollectionExtensions.AddComponentsMetrics(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.AspNetCore.Components.Infrastructure.ComponentsMetricsServiceCollectionExtensions.AddComponentsTracing(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions.AddSupplyValueFromPersistentComponentStateProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.AspNetCore.Components.Infrastructure.PersistentStateProviderServiceCollectionExtensions.AddSupplyValueFromPersistentComponentStateProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
virtual Microsoft.AspNetCore.Components.Rendering.ComponentState.GetComponentKey() -> object?
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class RegisterPersistentComponentStateServiceCollectionExtensions
/// Saves <typeparamref name="TService"/> state when the application is persisting state and restores it at the appropriate time automatically.
/// </summary>
/// <remarks>
/// Only public properties annotated with <see cref="SupplyParameterFromPersistentComponentStateAttribute"/> are persisted and restored.
/// Only public properties annotated with <see cref="PersistentStateAttribute"/> are persisted and restored.
/// </remarks>
/// <typeparam name="TService">The service type to register for persistence.</typeparam>
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
Expand All @@ -34,7 +34,7 @@ public static class RegisterPersistentComponentStateServiceCollectionExtensions
// We look for the assembly in the current list of loaded assemblies.
// We look for the type inside the assembly.
// We resolve the service from the DI container.
// We loop through the properties in the type and try to restore the properties that have SupplyParameterFromPersistentComponentState on them.
// We loop through the properties in the type and try to restore the properties that have PersistentState on them.
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPersistentServiceRegistration>(new PersistentServiceRegistration<TService>(componentRenderMode)));
services.TryAddSingleton<RegisteredPersistentServiceRegistrationCollection>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ public async Task PersistStateAsync_PersistsServiceWithComplexState()

private class AnotherTestService
{
[SupplyParameterFromPersistentComponentState]
[PersistentState]
public string State { get; set; }
}

private class CustomerService
{
[SupplyParameterFromPersistentComponentState]
[PersistentState]
public Customer Customer { get; set; }
}

Expand All @@ -419,7 +419,7 @@ private class TestRenderMode : IComponentRenderMode

private class TestService
{
[SupplyParameterFromPersistentComponentState]
[PersistentState]
public string State { get; set; }
}

Expand Down Expand Up @@ -471,19 +471,19 @@ private class BaseService

private class DerivedOne : BaseService
{
[SupplyParameterFromPersistentComponentState]
[PersistentState]
public string State { get; set; }
}

private class DerivedTwo : BaseService
{
[SupplyParameterFromPersistentComponentState]
[PersistentState]
public string State { get; set; }
}

private class BaseServiceWithProperty
{
[SupplyParameterFromPersistentComponentState]
[PersistentState]
public string State { get; set; }
}

Expand Down
Loading
Loading