Skip to content

Attributes

[RateLimit("policy")]

Overrides the default rate limit policy for a specific dispatch handler. The generated endpoint applies the named policy via .RequireRateLimiting("policy").

[CommandHandler]
[HttpPost("/orders")]
[RateLimit("ds_per_tenant")]
public static Eff<AppRuntime, OrderCreated> Handle(CreateOrder cmd) => ...
Property Type Description
Policy string The rate limit policy name to apply

Built-In Policy Names

Use constants from DeepstagingRateLimitPolicies:

Constant Value Description
Global "ds_global" Fixed window across all requests
PerTenant "ds_per_tenant" Sliding window keyed by CorrelationContext.TenantId
PerUser "ds_per_user" Sliding window keyed by authenticated user ID
PerIp "ds_per_ip" Fixed window keyed by remote IP address

Usage Examples

// Strict per-user limit for sensitive operations
[CommandHandler]
[HttpPost("/transfers")]
[RateLimit("ds_per_user")]
public static Eff<AppRuntime, TransferResult> Handle(CreateTransfer cmd) => ...

// Per-IP limit for public endpoints
[QueryHandler]
[HttpGet("/products")]
[Public]
[RateLimit("ds_per_ip")]
public static Eff<AppRuntime, PaginatedResult<Product>> Handle(ListProducts query) => ...

Custom Policies

Register custom policies and reference them by name:

// In Program.cs
builder.Services.AddRateLimiter(options =>
{
    options.AddFixedWindowLimiter("strict_api", opt =>
    {
        opt.PermitLimit = 10;
        opt.Window = TimeSpan.FromMinutes(1);
    });
});

// On the handler
[CommandHandler]
[RateLimit("strict_api")]
public static Eff<AppRuntime, Result> Handle(SensitiveOperation cmd) => ...

[ConfigSection("Deepstaging:RateLimiting")]

Applied to RateLimitingOptions — binds all rate limiting configuration from appsettings.json. See Overview for the full property reference.