Skip to content

Add ConfigurePolicy and ClearRules to Operation Rate Limiting#25082

Merged
EngincanV merged 1 commit into
devfrom
enhance/operation-rate-limiting-configure-policy
Mar 13, 2026
Merged

Add ConfigurePolicy and ClearRules to Operation Rate Limiting#25082
EngincanV merged 1 commit into
devfrom
enhance/operation-rate-limiting-configure-policy

Conversation

@maliming

Copy link
Copy Markdown
Member

Reusable ABP modules can ship with built-in rate limiting policies (e.g., Account module defining Account.SendPasswordResetCode). Previously, downstream applications could only fully replace a policy by calling AddPolicy with the same name — there was no way to make partial modifications such as changing just the error code or adding an extra rule.

This PR introduces ConfigurePolicy on AbpOperationRateLimitingOptions, which modifies an existing policy without replacing it entirely. The builder is pre-populated with the existing rules and error code, so callers only express what changes. It throws AbpException if the policy name doesn't exist, catching typos at startup rather than silently doing nothing. It returns AbpOperationRateLimitingOptions for chaining.

A companion ClearRules method is added to OperationRateLimitingPolicyBuilder, allowing callers to clear all inherited rules before defining new ones within ConfigurePolicy. An internal FromPolicy factory method reconstructs a builder from an existing built policy.

Additional improvements:

  • AddPolicy now returns AbpOperationRateLimitingOptions (was void) for chaining consistency with ConfigurePolicy
  • AddPolicy and FromPolicy now include parameter validation (Check.NotNullOrWhiteSpace / Check.NotNull)

Tests cover error code override, rule addition, ClearRules replacement, chaining, not-found exception, error code preservation, and same-name AddPolicy replacement. Documentation updated in both the reference doc and community article.

- Add ConfigurePolicy method to AbpOperationRateLimitingOptions for
  partial modification of existing policies without full replacement
- Add ClearRules method to OperationRateLimitingPolicyBuilder for
  clearing inherited rules before defining new ones
- Add FromPolicy factory method to reconstruct a builder from an
  existing policy
- Change AddPolicy return type to AbpOperationRateLimitingOptions
  for chaining consistency with ConfigurePolicy
- Add parameter validation to AddPolicy and FromPolicy
- Add documentation for overriding existing policies
- Add tests for ConfigurePolicy, ClearRules, chaining, and error cases
Copilot AI review requested due to automatic review settings March 13, 2026 05:40
@maliming maliming changed the title Add \ConfigurePolicy\ and \ClearRules\ to Operation Rate Limiting Add ConfigurePolicy and ClearRules to Operation Rate Limiting Mar 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a non-destructive configuration API for operation rate limiting policies so downstream modules/apps can adjust existing policies (e.g., change error code, add rules) without fully replacing them, plus supporting docs/tests.

Changes:

  • Introduces AbpOperationRateLimitingOptions.ConfigurePolicy(...) to modify an existing named policy using a builder pre-populated from the current policy.
  • Adds OperationRateLimitingPolicyBuilder.ClearRules() and internal FromPolicy(...) to enable “inherit then tweak” or “clear then replace” flows.
  • Expands test coverage and updates docs to describe full replacement (AddPolicy) vs partial modification (ConfigurePolicy).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
framework/test/Volo.Abp.OperationRateLimiting.Tests/Volo/Abp/OperationRateLimiting/OperationRateLimitingPolicyBuilder_Tests.cs Adds tests for ConfigurePolicy, ClearRules, chaining, and same-name AddPolicy replacement behavior.
framework/src/Volo.Abp.OperationRateLimiting/Volo/Abp/OperationRateLimiting/Policies/OperationRateLimitingPolicyBuilder.cs Adds ClearRules() and internal FromPolicy(...) builder reconstruction.
framework/src/Volo.Abp.OperationRateLimiting/Volo/Abp/OperationRateLimiting/AbpOperationRateLimitingOptions.cs Adds ConfigurePolicy(...) and updates AddPolicy to be fluent and validated.
docs/en/framework/infrastructure/operation-rate-limiting.md Documents the new customization workflow and the difference between replacing vs configuring.
docs/en/Community-Articles/2026-03-10-Operation-Rate-Limiting-in-ABP-Framework/POST.md Updates community article with guidance and examples for policy customization.

@maliming maliming added this to the 10.3-preview milestone Mar 13, 2026
@maliming maliming requested a review from EngincanV March 13, 2026 06:39
@EngincanV EngincanV merged commit 61d748c into dev Mar 13, 2026
7 checks passed
@EngincanV EngincanV deleted the enhance/operation-rate-limiting-configure-policy branch March 13, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants