2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using Microsoft . AspNetCore . Components ;
5
- using Microsoft . Extensions . DependencyInjection . Extensions ;
6
5
7
6
namespace Microsoft . Extensions . DependencyInjection ;
8
7
@@ -17,11 +16,11 @@ public static class CascadingValueServiceCollectionExtensions
17
16
/// </summary>
18
17
/// <typeparam name="TValue">The value type.</typeparam>
19
18
/// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
20
- /// <param name="initialValueFactory ">A callback that supplies a fixed value within each service provider scope.</param>
19
+ /// <param name="valueFactory ">A callback that supplies a fixed value within each service provider scope.</param>
21
20
/// <returns>The <see cref="IServiceCollection"/>.</returns>
22
21
public static IServiceCollection AddCascadingValue < TValue > (
23
- this IServiceCollection serviceCollection , Func < IServiceProvider , TValue > initialValueFactory )
24
- => serviceCollection . AddScoped < ICascadingValueSupplier > ( sp => new CascadingValueSource < TValue > ( ( ) => initialValueFactory ( sp ) , isFixed : true ) ) ;
22
+ this IServiceCollection serviceCollection , Func < IServiceProvider , TValue > valueFactory )
23
+ => serviceCollection . AddScoped < ICascadingValueSupplier > ( sp => new CascadingValueSource < TValue > ( ( ) => valueFactory ( sp ) , isFixed : true ) ) ;
25
24
26
25
/// <summary>
27
26
/// Adds a cascading value to the <paramref name="serviceCollection"/>. This is equivalent to having
@@ -30,11 +29,11 @@ public static IServiceCollection AddCascadingValue<TValue>(
30
29
/// <typeparam name="TValue">The value type.</typeparam>
31
30
/// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
32
31
/// <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="initialValueFactory ">A callback that supplies a fixed value within each service provider scope.</param>
32
+ /// <param name="valueFactory ">A callback that supplies a fixed value within each service provider scope.</param>
34
33
/// <returns>The <see cref="IServiceCollection"/>.</returns>
35
34
public static IServiceCollection AddCascadingValue < TValue > (
36
- this IServiceCollection serviceCollection , string name , Func < IServiceProvider , TValue > initialValueFactory )
37
- => serviceCollection . AddScoped < ICascadingValueSupplier > ( sp => new CascadingValueSource < TValue > ( name , ( ) => initialValueFactory ( sp ) , isFixed : true ) ) ;
35
+ this IServiceCollection serviceCollection , string name , Func < IServiceProvider , TValue > valueFactory )
36
+ => serviceCollection . AddScoped < ICascadingValueSupplier > ( sp => new CascadingValueSource < TValue > ( name , ( ) => valueFactory ( sp ) , isFixed : true ) ) ;
38
37
39
38
/// <summary>
40
39
/// Adds a cascading value to the <paramref name="serviceCollection"/>. This is equivalent to having
@@ -51,59 +50,4 @@ public static IServiceCollection AddCascadingValue<TValue>(
51
50
public static IServiceCollection AddCascadingValue < TValue > (
52
51
this IServiceCollection serviceCollection , Func < IServiceProvider , CascadingValueSource < TValue > > sourceFactory )
53
52
=> serviceCollection . AddScoped < ICascadingValueSupplier > ( sourceFactory ) ;
54
-
55
- /// <summary>
56
- /// Adds a cascading value to the <paramref name="serviceCollection"/>, if none is already registered
57
- /// with the value type. This is equivalent to having a fixed <see cref="CascadingValue{TValue}"/> at
58
- /// the root of the component hierarchy.
59
- /// </summary>
60
- /// <typeparam name="TValue">The value type.</typeparam>
61
- /// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
62
- /// <param name="valueFactory">A callback that supplies a fixed value within each service provider scope.</param>
63
- /// <returns>The <see cref="IServiceCollection"/>.</returns>
64
- public static void TryAddCascadingValue < TValue > (
65
- this IServiceCollection serviceCollection , Func < IServiceProvider , TValue > valueFactory )
66
- {
67
- serviceCollection . TryAddEnumerable (
68
- ServiceDescriptor . Scoped < ICascadingValueSupplier , CascadingValueSource < TValue > > (
69
- sp => new CascadingValueSource < TValue > ( ( ) => valueFactory ( sp ) , isFixed : true ) ) ) ;
70
- }
71
-
72
- /// <summary>
73
- /// Adds a cascading value to the <paramref name="serviceCollection"/>, if none is already registered
74
- /// with the value type, regardless of the <paramref name="name"/>. This is equivalent to having a fixed
75
- /// <see cref="CascadingValue{TValue}"/> at the root of the component hierarchy.
76
- /// </summary>
77
- /// <typeparam name="TValue">The value type.</typeparam>
78
- /// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
79
- /// <param name="name">A name for the cascading value. If set, <see cref="CascadingParameterAttribute"/> can be configured to match based on this name.</param>
80
- /// <param name="valueFactory">A callback that supplies a fixed value within each service provider scope.</param>
81
- /// <returns>The <see cref="IServiceCollection"/>.</returns>
82
- public static void TryAddCascadingValue < TValue > (
83
- this IServiceCollection serviceCollection , string name , Func < IServiceProvider , TValue > valueFactory )
84
- {
85
- serviceCollection . TryAddEnumerable (
86
- ServiceDescriptor . Scoped < ICascadingValueSupplier , CascadingValueSource < TValue > > (
87
- sp => new CascadingValueSource < TValue > ( name , ( ) => valueFactory ( sp ) , isFixed : true ) ) ) ;
88
- }
89
-
90
- /// <summary>
91
- /// Adds a cascading value to the <paramref name="serviceCollection"/>, if none is already registered
92
- /// with the value type. This is equivalent to having a fixed <see cref="CascadingValue{TValue}"/> at
93
- /// the root of the component hierarchy.
94
- ///
95
- /// With this overload, you can supply a <see cref="CascadingValueSource{TValue}"/> which allows you
96
- /// to notify about updates to the value later, causing recipients to re-render. This overload should
97
- /// only be used if you plan to update the value dynamically.
98
- /// </summary>
99
- /// <typeparam name="TValue">The value type.</typeparam>
100
- /// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
101
- /// <param name="sourceFactory">A callback that supplies a <see cref="CascadingValueSource{TValue}"/> within each service provider scope.</param>
102
- /// <returns>The <see cref="IServiceCollection"/>.</returns>
103
- public static void TryAddCascadingValue < TValue > (
104
- this IServiceCollection serviceCollection , Func < IServiceProvider , CascadingValueSource < TValue > > sourceFactory )
105
- {
106
- serviceCollection . TryAddEnumerable (
107
- ServiceDescriptor . Scoped < ICascadingValueSupplier , CascadingValueSource < TValue > > ( sourceFactory ) ) ;
108
- }
109
53
}
0 commit comments