Defines a generalized conditional policy for applying resource-level operations.
Implementations of ResourceCondition are used to determine whether a given cross-cutting concern (such as caching, rate limiting, retrying, or metering) should be applied to a specific operation invocation.
This abstraction decouples when an operation should be affected by a resource control policy from how it is applied.
The shouldApply method is invoked at runtime with an OperationContext providing contextual information such as:
- The method being executed
- Input arguments and metadata
- The returned result or thrown exception
Example
class OnlyForPremiumUsers extends ResourceCondition {
const OnlyForPremiumUsers();
@override
FutureOr<bool> shouldApply(OperationContext context) {
final user = context.getArgument('user');
return user?.isPremium == true;
}
}
Built-in conditions include:
- WhenAlways — always applies
- WhenNever — never applies
- WhenAll, WhenAny, WhenNot — logical combinators
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shouldApply(
OperationContext context) → FutureOr< bool> - Determines whether the operation should be subjected to a resource policy.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited