Add ConfigurePolicy and ClearRules to Operation Rate Limiting#25082
Merged
Conversation
- 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
ConfigurePolicy\ and \ClearRules\ to Operation Rate LimitingConfigurePolicy and ClearRules to Operation Rate Limiting
Contributor
There was a problem hiding this comment.
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 internalFromPolicy(...)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. |
EngincanV
approved these changes
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 callingAddPolicywith 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
ConfigurePolicyonAbpOperationRateLimitingOptions, 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 throwsAbpExceptionif the policy name doesn't exist, catching typos at startup rather than silently doing nothing. It returnsAbpOperationRateLimitingOptionsfor chaining.A companion
ClearRulesmethod is added toOperationRateLimitingPolicyBuilder, allowing callers to clear all inherited rules before defining new ones withinConfigurePolicy. An internalFromPolicyfactory method reconstructs a builder from an existing built policy.Additional improvements:
AddPolicynow returnsAbpOperationRateLimitingOptions(wasvoid) for chaining consistency withConfigurePolicyAddPolicyandFromPolicynow include parameter validation (Check.NotNullOrWhiteSpace/Check.NotNull)Tests cover error code override, rule addition,
ClearRulesreplacement, chaining, not-found exception, error code preservation, and same-nameAddPolicyreplacement. Documentation updated in both the reference doc and community article.