intercept library
π Jetleaf Core Interception (AOP) Subsystem
This library provides runtime method-level interception and cross-cutting concern management for Jetleaf applications. It enables behaviors such as auditing, logging, performance metrics, security authorization, and transaction boundaries to be applied cleanly and declaratively.
βοΈ Interceptor Chain Pipeline
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Method Invocation β
β service.performAction() β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 1. MethodInterceptor 1 [Before Advice: Logging] β
β β β
β 2. MethodInterceptor 2 [Around Advice: Security / Auth] β
β β β
β 3. Target Execution [Original Method Body Executed] β
β β β
β 4. Return Value / After [After Returning / Exception Adviceβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π¦ Exports Categorization
π Dispatchers & Invocations
- AbstractMethodDispatcher β orchestrates interceptor chain traversal.
- MethodInvocation β encapsulates the targeted method, arguments, target instance, and proceed handle.
π‘οΈ Interceptor Contracts
- MethodInterceptor β interceptor interface implementing
invoke(MethodInvocation invocation). - DefaultMethodInterceptor β default delegating interceptor implementation.
InterceptRegistryβ registry mapping method signatures to interceptor chains.
π Interceptables
- Interceptable β mixin enabling target classes to participate in method interception pipelines.
π― Usage Example: Custom Logging Method Interceptor
import 'package:jetleaf_core/intercept.dart';
class AuditLoggingInterceptor implements MethodInterceptor {
@override
Future<Object?> invoke(MethodInvocation invocation) async {
final methodName = invocation.getMethod().getName();
print('[AOP BEFORE] Invoking method: $methodName');
final stopwatch = Stopwatch()..start();
try {
final result = await invocation.proceed();
print('[AOP AFTER] Method $methodName completed in ${stopwatch.elapsedMilliseconds} ms');
return result;
} catch (e) {
print('[AOP ERROR] Method $methodName threw: $e');
rethrow;
}
}
}
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.
- InterceptorDependencyCycle
- A DependencyCycle implementation that represents a circular dependency between method interceptors in the interceptor chain.
- 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.