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.
Background and Motivation
The most common approach when it comes to configuring options/settings in
AddXXX,UseXXXandMapXXXmethods during project setup is to use the Action-based approach.For example AddControllers uses
not
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
Proposed API
Instead of providing the object based API, provide an Action based one instead:
Usage Examples
Risks
We are still in previews so there isn't a breaking change risk.