Skip to content

Commit e4d20da

Browse files
authored
[Blazor] Implement API review feedback: rename pause/resume methods and PersistentState attribute (#62549)
Fixes #62373 Fixes #61138
1 parent c18e93a commit e4d20da

24 files changed

+84
-82
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ BenchmarkDotNet.Artifacts/
1313
src/SignalR/clients/**/dist/
1414
modules/
1515
.ionide/
16+
TestResults/
1617

1718
# File extensions
1819
*.aps
@@ -33,6 +34,7 @@ modules/
3334
*.suo
3435
*.svclog
3536
*.tlog
37+
*.trx
3638
*.user
3739
*.userprefs
3840
*.vspx

src/Components/Components/src/PersistentState/PersistentServicesRegistry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ public PropertiesAccessor([DynamicallyAccessedMembers(LinkerFlags.Component)] Ty
166166
var keys = new List<(string, Type)>();
167167
foreach (var propertyInfo in GetCandidateBindableProperties(targetType))
168168
{
169-
SupplyParameterFromPersistentComponentStateAttribute? parameterAttribute = null;
169+
PersistentStateAttribute? parameterAttribute = null;
170170
foreach (var attribute in propertyInfo.GetCustomAttributes())
171171
{
172-
if (attribute is SupplyParameterFromPersistentComponentStateAttribute persistentStateAttribute)
172+
if (attribute is PersistentStateAttribute persistentStateAttribute)
173173
{
174174
parameterAttribute = persistentStateAttribute;
175175
break;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ namespace Microsoft.AspNetCore.Components;
88
/// previous render.
99
/// </summary>
1010
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
11-
public sealed class SupplyParameterFromPersistentComponentStateAttribute : CascadingParameterAttributeBase
11+
public sealed class PersistentStateAttribute : CascadingParameterAttributeBase
1212
{
1313
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.AspNetCore.Components;
4+
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.DependencyInjection.Extensions;
66

7-
namespace Microsoft.Extensions.DependencyInjection;
7+
namespace Microsoft.AspNetCore.Components.Infrastructure;
88

99
/// <summary>
10-
/// Enables component parameters to be supplied from <see cref="PersistentComponentState"/> with <see cref="SupplyParameterFromPersistentComponentStateAttribute"/>.
10+
/// Enables component parameters to be supplied from <see cref="PersistentComponentState"/> with <see cref="PersistentStateAttribute"/>.
1111
/// </summary>
12-
public static class SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions
12+
public static class PersistentStateProviderServiceCollectionExtensions
1313
{
1414
/// <summary>
15-
/// Enables component parameters to be supplied from <see cref="PersistentComponentState"/> with <see cref="SupplyParameterFromPersistentComponentStateAttribute"/>..
15+
/// Enables component parameters to be supplied from <see cref="PersistentComponentState"/> with <see cref="PersistentStateAttribute"/>.
1616
/// </summary>
1717
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
1818
/// <returns>The <see cref="IServiceCollection"/>.</returns>
1919
public static IServiceCollection AddSupplyValueFromPersistentComponentStateProvider(this IServiceCollection services)
2020
{
21-
services.TryAddEnumerable(ServiceDescriptor.Scoped<ICascadingValueSupplier, SupplyParameterFromPersistentComponentStateValueProvider>());
21+
services.TryAddEnumerable(ServiceDescriptor.Scoped<ICascadingValueSupplier, PersistentStateValueProvider>());
2222
return services;
2323
}
2424
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
using Microsoft.AspNetCore.Components.Rendering;
1414
using Microsoft.AspNetCore.Internal;
1515

16-
namespace Microsoft.AspNetCore.Components;
16+
namespace Microsoft.AspNetCore.Components.Infrastructure;
1717

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

2929
public bool CanSupplyValue(in CascadingParameterInfo parameterInfo)
30-
=> parameterInfo.Attribute is SupplyParameterFromPersistentComponentStateAttribute;
30+
=> parameterInfo.Attribute is PersistentStateAttribute;
3131

3232
[UnconditionalSuppressMessage(
3333
"ReflectionAnalysis",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Microsoft.AspNetCore.Components.Routing.NotFoundEventArgs.Path.get -> string!
1313
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.ComponentStatePersistenceManager(Microsoft.Extensions.Logging.ILogger<Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager!>! logger, System.IServiceProvider! serviceProvider) -> void
1414
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.SetPlatformRenderMode(Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
1515
Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions
16-
Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateAttribute
17-
Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateAttribute.SupplyParameterFromPersistentComponentStateAttribute() -> void
18-
Microsoft.Extensions.DependencyInjection.SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions
16+
Microsoft.AspNetCore.Components.PersistentStateAttribute
17+
Microsoft.AspNetCore.Components.PersistentStateAttribute.PersistentStateAttribute() -> void
18+
Microsoft.AspNetCore.Components.Infrastructure.PersistentStateProviderServiceCollectionExtensions
1919
static Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions.AddPersistentServiceRegistration<TService>(Microsoft.Extensions.DependencyInjection.IServiceCollection! services, Microsoft.AspNetCore.Components.IComponentRenderMode! componentRenderMode) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
2020
static Microsoft.AspNetCore.Components.Infrastructure.ComponentsMetricsServiceCollectionExtensions.AddComponentsMetrics(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
2121
static Microsoft.AspNetCore.Components.Infrastructure.ComponentsMetricsServiceCollectionExtensions.AddComponentsTracing(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
22-
static Microsoft.Extensions.DependencyInjection.SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions.AddSupplyValueFromPersistentComponentStateProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
22+
static Microsoft.AspNetCore.Components.Infrastructure.PersistentStateProviderServiceCollectionExtensions.AddSupplyValueFromPersistentComponentStateProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
2323
virtual Microsoft.AspNetCore.Components.Rendering.ComponentState.GetComponentKey() -> object?

src/Components/Components/src/RegisterPersistentComponentStateServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class RegisterPersistentComponentStateServiceCollectionExtensions
1717
/// Saves <typeparamref name="TService"/> state when the application is persisting state and restores it at the appropriate time automatically.
1818
/// </summary>
1919
/// <remarks>
20-
/// Only public properties annotated with <see cref="SupplyParameterFromPersistentComponentStateAttribute"/> are persisted and restored.
20+
/// Only public properties annotated with <see cref="PersistentStateAttribute"/> are persisted and restored.
2121
/// </remarks>
2222
/// <typeparam name="TService">The service type to register for persistence.</typeparam>
2323
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
@@ -34,7 +34,7 @@ public static class RegisterPersistentComponentStateServiceCollectionExtensions
3434
// We look for the assembly in the current list of loaded assemblies.
3535
// We look for the type inside the assembly.
3636
// We resolve the service from the DI container.
37-
// We loop through the properties in the type and try to restore the properties that have SupplyParameterFromPersistentComponentState on them.
37+
// We loop through the properties in the type and try to restore the properties that have PersistentState on them.
3838
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPersistentServiceRegistration>(new PersistentServiceRegistration<TService>(componentRenderMode)));
3939
services.TryAddSingleton<RegisteredPersistentServiceRegistrationCollection>();
4040

src/Components/Components/test/PersistentState/PersistentServicesRegistryTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,13 @@ public async Task PersistStateAsync_PersistsServiceWithComplexState()
391391

392392
private class AnotherTestService
393393
{
394-
[SupplyParameterFromPersistentComponentState]
394+
[PersistentState]
395395
public string State { get; set; }
396396
}
397397

398398
private class CustomerService
399399
{
400-
[SupplyParameterFromPersistentComponentState]
400+
[PersistentState]
401401
public Customer Customer { get; set; }
402402
}
403403

@@ -419,7 +419,7 @@ private class TestRenderMode : IComponentRenderMode
419419

420420
private class TestService
421421
{
422-
[SupplyParameterFromPersistentComponentState]
422+
[PersistentState]
423423
public string State { get; set; }
424424
}
425425

@@ -471,19 +471,19 @@ private class BaseService
471471

472472
private class DerivedOne : BaseService
473473
{
474-
[SupplyParameterFromPersistentComponentState]
474+
[PersistentState]
475475
public string State { get; set; }
476476
}
477477

478478
private class DerivedTwo : BaseService
479479
{
480-
[SupplyParameterFromPersistentComponentState]
480+
[PersistentState]
481481
public string State { get; set; }
482482
}
483483

484484
private class BaseServiceWithProperty
485485
{
486-
[SupplyParameterFromPersistentComponentState]
486+
[PersistentState]
487487
public string State { get; set; }
488488
}
489489

0 commit comments

Comments
 (0)