1
- // Licensed to the .NET Foundation under one or more agreements.
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
8
8
namespace Microsoft . Extensions . DependencyInjection
9
9
{
10
10
/// <summary>
11
- /// Provides convenience extension methods to register <see cref="IPolicyRegistry{String}"/> and
12
- /// <see cref="IReadOnlyPolicyRegistry{String}"/> in the service collection.
11
+ /// Provides convenience extension methods to register <see cref="IPolicyRegistry{String}"/> and
12
+ /// <see cref="IReadOnlyPolicyRegistry{String}"/> in the service collection.
13
13
/// </summary>
14
14
public static class PollyServiceCollectionExtensions
15
15
{
16
16
/// <summary>
17
17
/// Registers an empty <see cref="PolicyRegistry"/> in the service collection with service types
18
- /// <see cref="IPolicyRegistry{String}"/>, and <see cref="IReadOnlyPolicyRegistry{String}"/> and returns
19
- /// the newly created registry.
18
+ /// <see cref="IPolicyRegistry{String}"/>, <see cref="IReadOnlyPolicyRegistry{String}"/>, and
19
+ /// <see cref="IConcurrentPolicyRegistry{String}"/> and returns the newly created registry.
20
20
/// </summary>
21
21
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
22
22
/// <returns>The newly created <see cref="IPolicyRegistry{String}"/>.</returns>
@@ -30,6 +30,8 @@ public static IPolicyRegistry<string> AddPolicyRegistry(this IServiceCollection
30
30
// Create an empty registry, register and return it as an instance. This is the best way to get a
31
31
// single instance registered using both interfaces.
32
32
var registry = new PolicyRegistry ( ) ;
33
+
34
+ services . AddSingleton < IConcurrentPolicyRegistry < string > > ( registry ) ;
33
35
services . AddSingleton < IPolicyRegistry < string > > ( registry ) ;
34
36
services . AddSingleton < IReadOnlyPolicyRegistry < string > > ( registry ) ;
35
37
@@ -38,8 +40,8 @@ public static IPolicyRegistry<string> AddPolicyRegistry(this IServiceCollection
38
40
39
41
/// <summary>
40
42
/// Registers the provided <see cref="IPolicyRegistry{String}"/> in the service collection with service types
41
- /// <see cref="IPolicyRegistry{String}"/>, and <see cref="IReadOnlyPolicyRegistry{String}"/> and returns
42
- /// the provided registry.
43
+ /// <see cref="IPolicyRegistry{String}"/>, <see cref="IReadOnlyPolicyRegistry{String}"/>, and
44
+ /// <see cref="IConcurrentPolicyRegistry{String}"/> and returns the provided registry.
43
45
/// </summary>
44
46
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
45
47
/// <param name="registry">The <see cref="IPolicyRegistry{String}"/>.</param>
@@ -59,13 +61,18 @@ public static IPolicyRegistry<string> AddPolicyRegistry(this IServiceCollection
59
61
services . AddSingleton < IPolicyRegistry < string > > ( registry ) ;
60
62
services . AddSingleton < IReadOnlyPolicyRegistry < string > > ( registry ) ;
61
63
64
+ if ( registry is IConcurrentPolicyRegistry < string > concurrentRegistry )
65
+ {
66
+ services . AddSingleton < IConcurrentPolicyRegistry < string > > ( concurrentRegistry ) ;
67
+ }
68
+
62
69
return registry ;
63
70
}
64
71
65
72
/// <summary>
66
73
/// Registers an empty <see cref="PolicyRegistry"/> in the service collection with service types
67
- /// <see cref="IPolicyRegistry{String}"/>, and <see cref="IReadOnlyPolicyRegistry{String}"/> and
68
- /// uses the specified delegate to configure it.
74
+ /// <see cref="IPolicyRegistry{String}"/>, <see cref="IReadOnlyPolicyRegistry{String}"/>, and
75
+ /// <see cref="IConcurrentPolicyRegistry{String}"/> and uses the specified delegate to configure it.
69
76
/// </summary>
70
77
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
71
78
/// <param name="configureRegistry">A delegate that is used to configure an <see cref="IPolicyRegistry{String}"/>.</param>
@@ -93,6 +100,7 @@ public static IServiceCollection AddPolicyRegistry(this IServiceCollection servi
93
100
return registry ;
94
101
} ) ;
95
102
103
+ services . AddSingleton < IConcurrentPolicyRegistry < string > > ( serviceProvider => serviceProvider . GetRequiredService < PolicyRegistry > ( ) ) ;
96
104
services . AddSingleton < IPolicyRegistry < string > > ( serviceProvider => serviceProvider . GetRequiredService < PolicyRegistry > ( ) ) ;
97
105
services . AddSingleton < IReadOnlyPolicyRegistry < string > > ( serviceProvider => serviceProvider . GetRequiredService < PolicyRegistry > ( ) ) ;
98
106
0 commit comments