Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
namespace Microsoft.Extensions.DependencyInjection
{
using EasyCaching.Core;
using EasyCaching.Core.Configurations;
using System;
using EasyCaching.Core.Configurations;
using System;

/// <summary>
/// EasyCaching service collection extensions.
/// </summary>
public static class EasyCachingServiceCollectionExtensions
{
/// <summary>
/// Adds the easycaching.
/// Adds the EasyCaching.
/// </summary>
/// <returns>The easy caching.</returns>
/// <param name="services">Services.</param>
Expand All @@ -30,5 +30,38 @@ public static IServiceCollection AddEasyCaching(this IServiceCollection services

return services;
}

/// <summary>
/// Adds the EasyCaching.
/// </summary>
/// <returns>The easy caching.</returns>
/// <param name="services">Services.</param>
/// <param name="setupAction">Setup action.</param>
public static IServiceCollection AddEasyCaching(this IServiceCollection services, Action<IServiceProvider, EasyCachingOptions> 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<EasyCachingOptions>();
foreach (var serviceExtension in options.Extensions)
{
serviceExtension.AddServices(services);
}

return options;
});

return services;
}
}
}