intercept library Interception
🔄 JetLeaf Core Interception
This library provides support for method-level interception and cross-cutting concerns in JetLeaf applications. It enables behaviors such as logging, metrics collection, transaction management, and custom method interception to be applied declaratively to objects.
Example
import 'package:jetleaf_core/intercept.dart';
class UserService with Interceptable {
@LogExecution()
Future<String> greet(String name) async => when(() async {
return 'Hello, $name';
});
}
In this example, the Interceptable mixin allows JetLeaf to
automatically apply cross-cutting behaviors to the greet
method using the @LogExecution annotation.
🔑 Core Components
Method Dispatching
abstract_method_dispatcher.dart— base abstraction for dispatching method invocations through interceptors
Interceptors
method_interceptor.dart— defines the interceptor interfacedefault_method_interceptor.dart— default method interceptor implementation
Interceptable Objects
interceptable.dart— mixin that makes classes interceptable and supports method interception hooksmethod_invocation.dart— encapsulates method invocation details for interceptionmethod_argument.dart— represents method arguments for intercepted calls
Interceptor Management
intercept_registry.dart— manages and registers method interceptors for various classes and methods
🎯 Intended Usage
Import this library to add cross-cutting behaviors to your
services or components. Use the Interceptable mixin along with
method annotations to declaratively apply interceptors:
class LoggingService with Interceptable {
@LogExecution()
void performAction() {
// Logging occurs automatically before and after execution
}
}
Provides a foundation for AOP-style programming in JetLeaf.
Classes
- AbstractMethodDispatcher
- A foundational implementation of MethodInterceptorDispatcher and MethodInterceptor providing a unified interception pipeline for JetLeaf's runtime and AOP subsystems.
- AfterInvocationInterceptor
- Defines an interceptor that executes after method completion, regardless of whether the invocation succeeded or failed.
- AfterReturningInterceptor
- An interceptor that executes after a method successfully returns a value, without throwing an exception.
- AfterThrowingInterceptor
- An interceptor triggered when a target method throws an exception.
- AroundMethodInterceptor
- A comprehensive interceptor that wraps the entire method invocation process, allowing developers to control when and how the target method executes.
- DefaultMethodInterceptor
- Default implementation of MethodInterceptorRegistry and related intercept processing.
- Interceptable
- Provides runtime interception support for method invocations within JetLeaf-managed components.
- MethodBeforeInterceptor
- Defines an interceptor that executes logic before the target method invocation begins.
- MethodInterceptor
- Defines the core interception contract for JetLeaf’s AOP (Aspect-Oriented Programming) framework, allowing runtime interception and augmentation of method invocations.
- MethodInterceptorConfigurer
- Strategy interface for configuring method interceptors in JetLeaf intercept.
- MethodInterceptorDispatcher
- Defines an advanced interception dispatcher that coordinates multiple method interceptors.
- MethodInterceptorRegistry
- Central registry for managing method-level interceptors and their dispatching.
-
MethodInvocation<
T> - Represents a reflective method invocation within the interception pipeline.
-
SimpleMethodInvocation<
T> - Represents a reflective invocation of a method on a target object, forming the core join point within JetLeaf’s interception system.
Typedefs
-
AsyncMethodInvocator<
T> = Future< T> Function() - Represents a deferred executable function that performs a method invocation.