6
6
using Microsoft . Extensions . DependencyInjection . Extensions ;
7
7
using Microsoft . Extensions . Options ;
8
8
using ServiceStack . Redis ;
9
+ using static System . Collections . Specialized . BitVector32 ;
9
10
10
11
namespace Microsoft . Extensions . DependencyInjection
11
12
{
@@ -24,34 +25,31 @@ public static IServiceCollection AddDistributedServiceStackRedisCache(this IServ
24
25
throw new ArgumentNullException ( nameof ( setupAction ) ) ;
25
26
}
26
27
27
- services . AddOptions ( ) ;
28
- services . Configure ( setupAction ) ;
29
- services . TryAddSingleton < IDistributedCache , ServiceStackRedisCache > ( ) ;
30
-
31
- return services ;
28
+ return services . AddDistributedServiceStackRedisCache (
29
+ services => setupAction ( services ) ) ;
32
30
}
33
31
34
- #if NET6_0_OR_GREATER
35
32
public static IServiceCollection AddDistributedServiceStackRedisCache ( this IServiceCollection services , string configName )
36
33
{
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 ) ) ;
39
36
}
40
- #endif
41
37
42
38
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 )
43
45
{
44
46
if ( services == null )
45
47
{
46
48
throw new ArgumentNullException ( nameof ( services ) ) ;
47
49
}
48
50
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 ) ;
55
53
56
54
services . TryAddSingleton < IRedisClientsManager > ( provider =>
57
55
{
0 commit comments