Skip to content

[API Proposal]: Make RateLimitPartition.Factory public #70597

@wtgodbe

Description

@wtgodbe

Background and motivation

This will allow aspnetcore's RateLimitingMiddleware to resolve a Limiter from a given TKey without having to use reflection. The use case is that users provide a Func<HttpContext, RateLimitPartition<TKey>>, which we want to convert to a Func<HttpContext, RateLimitPartition<AspNetKey<TKey>>> (using Factory) - AspNetKey being used to remove possible ambiguities between TKeys.

API Proposal

namespace System.Threading.RateLimiting
{
    public struct RateLimitPartition<TKey>
    {
        public RateLimitPartition(TKey partitionKey, Func<TKey, RateLimiter> factory)
        public TKey PartitionKey { get; }
+       public Func<TKey, RateLimiter> Factory {get; }
}

API Usage

RateLimiter limiter = partition.Factory("MyLimiter");

Alternative Designs

The other option is to use private reflection

Risks

N/A?

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.ThreadingblockingMarks issues that we want to fast track in order to unblock other important work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions