public void Create() { var keyEvaluator = QosPolicyKeyEvaluator.Create(c => c.Policy.Name); var result = keyEvaluator.GetKey(new QosPolicyKeyContext() { Policy = new QosPolicy("ABC") }); Assert.Equal("ABC", result); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IQosRejectResponse, MyCustomQosRejectResponse>(); services.AddSingleton <IQosPolicyProvider, MyCustomPolicyProvider>(); services.AddSingleton <IQosPolicyPostConfigure, MyCustomPolicyPostConfigure>(); services.AddQosRedisStore(o => o.Configuration = "localhost"); services.AddQos(); services.AddQosExpressionPolicyKeyEvaluator(); services.Configure <QosVipOptions>(Configuration.GetSection("Vip")); services.AddQosVip(); services.Configure <QosConcurrencyOptions>(Configuration.GetSection("Concurrency")); services.AddQosConcurrency(); services.Configure <QosRateLimitOptions>(Configuration.GetSection("RateLimit")); services.PostConfigure <QosRateLimitOptions>(o => { o.Policies.Add("R_HARDCODED", new QosRateLimitPolicy() { MaxCount = 2, Period = new TimeSpan(0, 0, 30), UrlTemplates = new[] { "/api/ratelimit2" }, Key = QosPolicyKeyEvaluator.Create(c => c.HttpContext.Connection.RemoteIpAddress.ToString()) }); }); services.AddQosRateLimit(); services.Configure <QosQuotaOptions>(Configuration.GetSection("Quota")); services.AddQosQuota(); services.AddQosMvc(); services.AddMvc(); }