Defines an interceptor that executes logic before the target method invocation begins.
Implementations of this interface can perform pre-processing steps such as:
- Security and authorization checks
- Logging or auditing
- Context or transaction initialization
Invocation Order
- The interceptor’s beforeInvocation is executed.
- If successful, the target method (or next interceptor) is invoked.
- If beforeInvocation throws an exception, invocation halts.
Example
class LoggingInterceptor implements MethodBeforeInterceptor {
@override
bool canIntercept(Method method) => true;
@override
Future<void> beforeInvocation<T>(MethodInvocation<T> invocation) async {
print("Calling method: ${invocation.method.getName()}");
}
}
See Also
- Implemented types
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
-
beforeInvocation<
T> (MethodInvocation< T> invocation) → FutureOr<void> - Executed immediately before the target method invocation.
-
canIntercept(
Method method) → bool -
Determines whether this interceptor can intercept the specified
method.inherited -
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited