@@ -16,9 +16,10 @@ public static class ServiceCollectionExtensions
1616 /// </summary>
1717 /// <param name="collection">The services collection.</param>
1818 /// <param name="configure">The <see cref="CacheManager.Core.ConfigurationBuilder"/> used for defining the <see cref="ICacheManagerConfiguration"/>.</param>
19- /// <param name="name">The (optional) name to be used for the configuration .</param>
19+ /// <param name="name">The (optional) name to be used for the <see cref="ICacheManagerConfiguration"/> .</param>
2020 public static IServiceCollection AddCacheManagerConfiguration ( this IServiceCollection collection , Action < CacheManager . Core . ConfigurationBuilder > configure , string name = null )
2121 {
22+ Guard . NotNull ( collection , nameof ( collection ) ) ;
2223 Guard . NotNull ( configure , nameof ( configure ) ) ;
2324 var builder = string . IsNullOrWhiteSpace ( name ) ?
2425 new CacheManager . Core . ConfigurationBuilder ( ) :
@@ -38,6 +39,7 @@ public static IServiceCollection AddCacheManagerConfiguration(this IServiceColle
3839 /// <returns>The services collection</returns>
3940 public static IServiceCollection AddCacheManagerConfiguration ( this IServiceCollection collection , IConfiguration fromConfiguration )
4041 {
42+ Guard . NotNull ( collection , nameof ( collection ) ) ;
4143 Guard . NotNull ( fromConfiguration , nameof ( fromConfiguration ) ) ;
4244 var configuration = fromConfiguration . GetCacheConfiguration ( ) ;
4345 collection . AddSingleton ( configuration ) ;
@@ -53,6 +55,7 @@ public static IServiceCollection AddCacheManagerConfiguration(this IServiceColle
5355 /// <returns>The services collection</returns>
5456 public static IServiceCollection AddCacheManagerConfiguration ( this IServiceCollection collection , IConfiguration fromConfiguration , string name )
5557 {
58+ Guard . NotNull ( collection , nameof ( collection ) ) ;
5659 Guard . NotNull ( fromConfiguration , nameof ( fromConfiguration ) ) ;
5760 var configuration = fromConfiguration . GetCacheConfiguration ( name ) ;
5861 collection . AddSingleton ( configuration ) ;
@@ -69,6 +72,7 @@ public static IServiceCollection AddCacheManagerConfiguration(this IServiceColle
6972 /// <returns>The services collection</returns>
7073 public static IServiceCollection AddCacheManagerConfiguration ( this IServiceCollection collection , IConfiguration fromConfiguration , Action < CacheManager . Core . ConfigurationBuilder > configure )
7174 {
75+ Guard . NotNull ( collection , nameof ( collection ) ) ;
7276 Guard . NotNull ( fromConfiguration , nameof ( fromConfiguration ) ) ;
7377 Guard . NotNull ( configure , nameof ( configure ) ) ;
7478
@@ -88,6 +92,7 @@ public static IServiceCollection AddCacheManagerConfiguration(this IServiceColle
8892 /// <returns>The services collection</returns>
8993 public static IServiceCollection AddCacheManagerConfiguration ( this IServiceCollection collection , IConfiguration fromConfiguration , string name , Action < CacheManager . Core . ConfigurationBuilder > configure )
9094 {
95+ Guard . NotNull ( collection , nameof ( collection ) ) ;
9196 Guard . NotNull ( fromConfiguration , nameof ( fromConfiguration ) ) ;
9297 Guard . NotNull ( configure , nameof ( configure ) ) ;
9398
@@ -110,6 +115,7 @@ public static IServiceCollection AddCacheManagerConfiguration(this IServiceColle
110115 /// <returns>The services collection.</returns>
111116 public static IServiceCollection AddCacheManager ( this IServiceCollection collection )
112117 {
118+ Guard . NotNull ( collection , nameof ( collection ) ) ;
113119 collection . AddSingleton ( typeof ( ICacheManager < > ) , typeof ( BaseCacheManager < > ) ) ;
114120
115121 return collection ;
@@ -127,8 +133,11 @@ public static IServiceCollection AddCacheManager(this IServiceCollection collect
127133 /// <param name="configurationName">The name of the <see cref="ICacheManagerConfiguration"/> to use.</param>
128134 /// <param name="configure">Can be used to further configure the <see cref="ICacheManagerConfiguration"/>.</param>
129135 /// <returns>The services collection.</returns>
130- public static IServiceCollection AddCacheManager < T > ( this IServiceCollection collection , IConfiguration fromConfiguration = null , string configurationName = null , Action < CacheManager . Core . ConfigurationBuilder > configure = null )
136+ public static IServiceCollection AddCacheManager < T > ( this IServiceCollection collection , IConfiguration fromConfiguration , string configurationName = null , Action < CacheManager . Core . ConfigurationBuilder > configure = null )
131137 {
138+ Guard . NotNull ( collection , nameof ( collection ) ) ;
139+ Guard . NotNull ( fromConfiguration , nameof ( fromConfiguration ) ) ;
140+
132141 collection . AddSingleton < ICacheManager < T > , BaseCacheManager < T > > ( ( provider ) =>
133142 {
134143 var configuration = string . IsNullOrWhiteSpace ( configurationName ) ? fromConfiguration . GetCacheConfiguration ( ) : fromConfiguration . GetCacheConfiguration ( configurationName ) ;
@@ -140,5 +149,33 @@ public static IServiceCollection AddCacheManager<T>(this IServiceCollection coll
140149
141150 return collection ;
142151 }
152+
153+ /// <summary>
154+ /// Adds a singleton service for <see cref="ICacheManager{TCacheValue}"/> for the specified <typeparamref name="T"/> to the <see cref="IServiceCollection"/>
155+ /// using the inline configuration defined by <paramref name="configure"/>.
156+ /// </summary>
157+ /// <param name="collection">The services collection.</param>
158+ /// <param name="configure">Used to configure the instance of <see cref="ICacheManager{TCacheValue}"/>.</param>
159+ /// <param name="name">The (optional) name for the <see cref="ICacheManagerConfiguration"/>.</param>
160+ /// <returns>The services collection.</returns>
161+ public static IServiceCollection AddCacheManager < T > ( this IServiceCollection collection , Action < CacheManager . Core . ConfigurationBuilder > configure , string name = null )
162+ {
163+ Guard . NotNull ( collection , nameof ( collection ) ) ;
164+ Guard . NotNull ( configure , nameof ( configure ) ) ;
165+
166+ collection . AddSingleton < ICacheManager < T > , BaseCacheManager < T > > ( ( provider ) =>
167+ {
168+ Guard . NotNull ( configure , nameof ( configure ) ) ;
169+ var builder = string . IsNullOrWhiteSpace ( name ) ?
170+ new CacheManager . Core . ConfigurationBuilder ( ) :
171+ new CacheManager . Core . ConfigurationBuilder ( name ) ;
172+
173+ configure ( builder ) ;
174+
175+ return new BaseCacheManager < T > ( builder . Build ( ) ) ;
176+ } ) ;
177+
178+ return collection ;
179+ }
143180 }
144181}
0 commit comments