Skip to content

UseRateLimiter API deviates by the Action-based config approach #41655

@Elfocrash

Description

@Elfocrash

Background and Motivation

The most common approach when it comes to configuring options/settings in AddXXX, UseXXX and MapXXX methods during project setup is to use the Action-based approach.
For example AddControllers uses

public static IMvcBuilder AddControllers(this IServiceCollection services, Action<MvcOptions>? configure){}

not

public static IMvcBuilder AddControllers(this IServiceCollection services, MvcOptions? options){}

Which in return is being invoced with the services.Configure(configure) method which registers them as Options.
This is pretty standard across most .NET APIs (and libraries).

The UserRateLimiter API is using the object based approach which feels out of place compared to the other ones

public static IApplicationBuilder UseRateLimiter(this IApplicationBuilder app, RateLimiterOptions options)

Proposed API

Instead of providing the object based API, provide an Action based one instead:

public static IApplicationBuilder UseRateLimiter(this IApplicationBuilder app, Action<RateLimiterOptions> configure)

Usage Examples

app.UseRateLimiter(options =>
{
    options.DefaultRejectionStatusCode = 429;
});

Risks

We are still in previews so there isn't a breaking change risk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions