/// <summary> /// Returns the policy for the specified name, or null if a policy with the name does not exist. /// </summary> /// <param name="name">The name of the policy to return.</param> /// <returns>The policy for the specified name, or null if a policy with the name does not exist.</returns> public AuthorizationPolicy GetPolicy(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } return(PolicyMap.ContainsKey(name) ? PolicyMap[name] : null); }
public ILinksPolicy GetPolicy <TResource>(string name) { if (String.IsNullOrEmpty(name)) { throw new ArgumentException("Policy name cannot be null", nameof(name)); } var policyName = $"{name}:{typeof(TResource).FullName}"; return(PolicyMap.ContainsKey(policyName) ? PolicyMap[policyName] as ILinksPolicy /*<TResource>*/ : null); }
public string GetPolicyFor(Type messageType) { Guard.AgainstNull(nameof(messageType), messageType); if (!PolicyMap.ContainsKey(messageType)) { return(null); } return(PolicyMap[messageType]); }
/// <summary> /// Adds a new rate limiting policy with the given <paramref name="policyName"/> /// </summary> /// <param name="policyName">The name to be associated with the given <see cref="RateLimiter"/>.</param> /// <param name="partitioner">Method called every time an Acquire or WaitAsync call is made to determine what rate limiter to apply to the request.</param> public RateLimiterOptions AddPolicy <TPartitionKey>(string policyName, Func <HttpContext, RateLimitPartition <TPartitionKey> > partitioner) { ArgumentNullException.ThrowIfNull(policyName); ArgumentNullException.ThrowIfNull(partitioner); if (PolicyMap.ContainsKey(policyName) || UnactivatedPolicyMap.ContainsKey(policyName)) { throw new ArgumentException($"There already exists a policy with the name {policyName}.", nameof(policyName)); } PolicyMap.Add(policyName, new DefaultRateLimiterPolicy(ConvertPartitioner <TPartitionKey>(policyName, partitioner), null)); return(this); }
/// <summary> /// Adds a new rate limiting policy with the given policyName. /// </summary> /// <param name="policyName">The name to be associated with the given <see cref="IRateLimiterPolicy{TPartitionKey}"/>.</param> /// <param name="policy">The <see cref="IRateLimiterPolicy{TPartitionKey}"/> to be applied.</param> public RateLimiterOptions AddPolicy <TPartitionKey>(string policyName, IRateLimiterPolicy <TPartitionKey> policy) { ArgumentNullException.ThrowIfNull(policyName); if (PolicyMap.ContainsKey(policyName) || UnactivatedPolicyMap.ContainsKey(policyName)) { throw new ArgumentException($"There already exists a policy with the name {policyName}.", nameof(policyName)); } ArgumentNullException.ThrowIfNull(policy); PolicyMap.Add(policyName, new DefaultRateLimiterPolicy(ConvertPartitioner <TPartitionKey>(policyName, policy.GetPartition), policy.OnRejected)); return(this); }
/// <summary> /// Adds a new rate limiting policy with the given policyName. /// </summary> /// <param name="policyName">The name to be associated with the given TPolicy.</param> public RateLimiterOptions AddPolicy <TPartitionKey, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TPolicy>(string policyName) where TPolicy : IRateLimiterPolicy <TPartitionKey> { ArgumentNullException.ThrowIfNull(policyName); if (PolicyMap.ContainsKey(policyName) || UnactivatedPolicyMap.ContainsKey(policyName)) { throw new ArgumentException($"There already exists a policy with the name {policyName}.", nameof(policyName)); } var policyType = new PolicyTypeState(typeof(TPolicy)); Func <IServiceProvider, DefaultRateLimiterPolicy> policyFunc = serviceProvider => { var instance = (IRateLimiterPolicy <TPartitionKey>)ActivatorUtilities.CreateInstance(serviceProvider, policyType.PolicyType); return(new DefaultRateLimiterPolicy(ConvertPartitioner <TPartitionKey>(policyName, instance.GetPartition), instance.OnRejected)); }; UnactivatedPolicyMap.Add(policyName, policyFunc); return(this); }
public AuthorizationPolicy GetPolicy([NotNull] string name) { return(PolicyMap.ContainsKey(name) ? PolicyMap[name] : null); }
/// <summary> /// Gets the policy based on the <paramref name="name"/> /// </summary> /// <param name="name">The name of the policy to lookup.</param> /// <returns>The <see cref="CorsPolicy"/> if the policy was added.<c>null</c> otherwise.</returns> public CorsPolicy GetPolicy([NotNull] string name) { return(PolicyMap.ContainsKey(name) ? PolicyMap[name] : null); }
internal bool HasDefaultPocily() { return(PolicyMap.ContainsKey(_defaultPolicyName)); }