1- // Licensed to the .NET Foundation under one or more agreements.
1+ // Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
88namespace Microsoft . Extensions . DependencyInjection
99{
1010 /// <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.
1313 /// </summary>
1414 public static class PollyServiceCollectionExtensions
1515 {
1616 /// <summary>
1717 /// 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.
2020 /// </summary>
2121 /// <param name="services">The <see cref="IServiceCollection"/>.</param>
2222 /// <returns>The newly created <see cref="IPolicyRegistry{String}"/>.</returns>
@@ -30,6 +30,8 @@ public static IPolicyRegistry<string> AddPolicyRegistry(this IServiceCollection
3030 // Create an empty registry, register and return it as an instance. This is the best way to get a
3131 // single instance registered using both interfaces.
3232 var registry = new PolicyRegistry ( ) ;
33+
34+ services . AddSingleton < IConcurrentPolicyRegistry < string > > ( registry ) ;
3335 services . AddSingleton < IPolicyRegistry < string > > ( registry ) ;
3436 services . AddSingleton < IReadOnlyPolicyRegistry < string > > ( registry ) ;
3537
@@ -38,8 +40,8 @@ public static IPolicyRegistry<string> AddPolicyRegistry(this IServiceCollection
3840
3941 /// <summary>
4042 /// 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.
4345 /// </summary>
4446 /// <param name="services">The <see cref="IServiceCollection"/>.</param>
4547 /// <param name="registry">The <see cref="IPolicyRegistry{String}"/>.</param>
@@ -59,13 +61,18 @@ public static IPolicyRegistry<string> AddPolicyRegistry(this IServiceCollection
5961 services . AddSingleton < IPolicyRegistry < string > > ( registry ) ;
6062 services . AddSingleton < IReadOnlyPolicyRegistry < string > > ( registry ) ;
6163
64+ if ( registry is IConcurrentPolicyRegistry < string > concurrentRegistry )
65+ {
66+ services . AddSingleton < IConcurrentPolicyRegistry < string > > ( concurrentRegistry ) ;
67+ }
68+
6269 return registry ;
6370 }
6471
6572 /// <summary>
6673 /// 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.
6976 /// </summary>
7077 /// <param name="services">The <see cref="IServiceCollection"/>.</param>
7178 /// <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
93100 return registry ;
94101 } ) ;
95102
103+ services . AddSingleton < IConcurrentPolicyRegistry < string > > ( serviceProvider => serviceProvider . GetRequiredService < PolicyRegistry > ( ) ) ;
96104 services . AddSingleton < IPolicyRegistry < string > > ( serviceProvider => serviceProvider . GetRequiredService < PolicyRegistry > ( ) ) ;
97105 services . AddSingleton < IReadOnlyPolicyRegistry < string > > ( serviceProvider => serviceProvider . GetRequiredService < PolicyRegistry > ( ) ) ;
98106
0 commit comments