1
1
namespace Microsoft . Extensions . DependencyInjection
2
2
{
3
3
using EasyCaching . Core ;
4
- using EasyCaching . Core . Configurations ;
5
- using System ;
4
+ using EasyCaching . Core . Configurations ;
5
+ using System ;
6
6
7
7
/// <summary>
8
8
/// EasyCaching service collection extensions.
9
9
/// </summary>
10
10
public static class EasyCachingServiceCollectionExtensions
11
11
{
12
12
/// <summary>
13
- /// Adds the easycaching .
13
+ /// Adds the EasyCaching .
14
14
/// </summary>
15
15
/// <returns>The easy caching.</returns>
16
16
/// <param name="services">Services.</param>
@@ -30,5 +30,38 @@ public static IServiceCollection AddEasyCaching(this IServiceCollection services
30
30
31
31
return services ;
32
32
}
33
+
34
+ /// <summary>
35
+ /// Adds the EasyCaching.
36
+ /// </summary>
37
+ /// <returns>The easy caching.</returns>
38
+ /// <param name="services">Services.</param>
39
+ /// <param name="setupAction">Setup action.</param>
40
+ public static IServiceCollection AddEasyCaching ( this IServiceCollection services , Action < IServiceProvider , EasyCachingOptions > setupAction )
41
+ {
42
+ ArgumentCheck . NotNull ( setupAction , nameof ( setupAction ) ) ;
43
+
44
+ // Options
45
+ services . AddSingleton ( sp =>
46
+ {
47
+ var options = new EasyCachingOptions ( ) ;
48
+ setupAction ( sp , options ) ;
49
+ return options ;
50
+ } ) ;
51
+
52
+ // Extension services
53
+ services . AddSingleton ( sp =>
54
+ {
55
+ var options = sp . GetRequiredService < EasyCachingOptions > ( ) ;
56
+ foreach ( var serviceExtension in options . Extensions )
57
+ {
58
+ serviceExtension . AddServices ( services ) ;
59
+ }
60
+
61
+ return options ;
62
+ } ) ;
63
+
64
+ return services ;
65
+ }
33
66
}
34
67
}
0 commit comments