using AspNetCoreRateLimit; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; namespace EntrustSettle.Extensions { /// /// IPLimit限流 启动服务 /// public static class IpPolicyRateLimitSetup { public static void AddIpPolicyRateLimitSetup(this IServiceCollection services, IConfiguration Configuration) { if (services == null) throw new ArgumentNullException(nameof(services)); // needed to store rate limit counters and ip rules services.AddMemoryCache(); //load general configuration from appsettings.json services.Configure(Configuration.GetSection("IpRateLimiting")); // inject counter and rules stores services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); // inject counter and rules distributed cache stores //services.AddSingleton(); //services.AddSingleton(); // the clientId/clientIp resolvers use it. services.AddSingleton(); // configuration (resolvers, counter key builders) services.AddSingleton(); } } }