diff --git a/src/EasyCaching.Core/Configurations/EasyCachingServiceCollectionExtensions.cs b/src/EasyCaching.Core/Configurations/EasyCachingServiceCollectionExtensions.cs index a3f105bc..2873dad9 100644 --- a/src/EasyCaching.Core/Configurations/EasyCachingServiceCollectionExtensions.cs +++ b/src/EasyCaching.Core/Configurations/EasyCachingServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ namespace Microsoft.Extensions.DependencyInjection { using EasyCaching.Core; - using EasyCaching.Core.Configurations; - using System; + using EasyCaching.Core.Configurations; + using System; /// /// EasyCaching service collection extensions. @@ -10,7 +10,7 @@ public static class EasyCachingServiceCollectionExtensions { /// - /// Adds the easycaching. + /// Adds the EasyCaching. /// /// The easy caching. /// Services. @@ -30,5 +30,38 @@ public static IServiceCollection AddEasyCaching(this IServiceCollection services return services; } + + /// + /// Adds the EasyCaching. + /// + /// The easy caching. + /// Services. + /// Setup action. + public static IServiceCollection AddEasyCaching(this IServiceCollection services, Action setupAction) + { + ArgumentCheck.NotNull(setupAction, nameof(setupAction)); + + // Options + services.AddSingleton(sp => + { + var options = new EasyCachingOptions(); + setupAction(sp, options); + return options; + }); + + // Extension services + services.AddSingleton(sp => + { + var options = sp.GetRequiredService(); + foreach (var serviceExtension in options.Extensions) + { + serviceExtension.AddServices(services); + } + + return options; + }); + + return services; + } } }