66using Microsoft . Extensions . DependencyInjection . Extensions ;
77using Microsoft . Extensions . Options ;
88using ServiceStack . Redis ;
9+ using static System . Collections . Specialized . BitVector32 ;
910
1011namespace Microsoft . Extensions . DependencyInjection
1112{
@@ -24,34 +25,31 @@ public static IServiceCollection AddDistributedServiceStackRedisCache(this IServ
2425 throw new ArgumentNullException ( nameof ( setupAction ) ) ;
2526 }
2627
27- services . AddOptions ( ) ;
28- services . Configure ( setupAction ) ;
29- services . TryAddSingleton < IDistributedCache , ServiceStackRedisCache > ( ) ;
30-
31- return services ;
28+ return services . AddDistributedServiceStackRedisCache (
29+ services => setupAction ( services ) ) ;
3230 }
3331
34- #if NET6_0_OR_GREATER
3532 public static IServiceCollection AddDistributedServiceStackRedisCache ( this IServiceCollection services , string configName )
3633 {
37- var config = services . BuildServiceProvider ( ) . GetRequiredService < IConfiguration > ( ) ;
38- return services . AddDistributedServiceStackRedisCache ( config . GetSection ( configName ) ) ;
34+ return services . AddDistributedServiceStackRedisCache (
35+ services => services . AddOptions < ServiceStackRedisCacheOptions > ( ) . BindConfiguration ( configName ) ) ;
3936 }
40- #endif
4137
4238 public static IServiceCollection AddDistributedServiceStackRedisCache ( this IServiceCollection services , IConfigurationSection section )
39+ {
40+ return services . AddDistributedServiceStackRedisCache (
41+ services => services . Configure < ServiceStackRedisCacheOptions > ( section ) ) ;
42+ }
43+
44+ public static IServiceCollection AddDistributedServiceStackRedisCache ( this IServiceCollection services , Action < IServiceCollection > configure )
4345 {
4446 if ( services == null )
4547 {
4648 throw new ArgumentNullException ( nameof ( services ) ) ;
4749 }
4850
49- if ( section == null )
50- {
51- throw new ArgumentNullException ( nameof ( section ) ) ;
52- }
53-
54- services . Configure < ServiceStackRedisCacheOptions > ( section ) ;
51+ services . AddOptions ( ) ;
52+ configure ? . Invoke ( services ) ;
5553
5654 services . TryAddSingleton < IRedisClientsManager > ( provider =>
5755 {
0 commit comments