11namespace Microsoft . Extensions . DependencyInjection
22{
33 using EasyCaching . Core ;
4- using EasyCaching . Core . Configurations ;
5- using System ;
4+ using EasyCaching . Core . Configurations ;
5+ using System ;
66
77 /// <summary>
88 /// EasyCaching service collection extensions.
99 /// </summary>
1010 public static class EasyCachingServiceCollectionExtensions
1111 {
1212 /// <summary>
13- /// Adds the easycaching .
13+ /// Adds the EasyCaching .
1414 /// </summary>
1515 /// <returns>The easy caching.</returns>
1616 /// <param name="services">Services.</param>
@@ -30,5 +30,38 @@ public static IServiceCollection AddEasyCaching(this IServiceCollection services
3030
3131 return services ;
3232 }
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+ }
3366 }
3467}
0 commit comments