ProxyBuilder constructor
ProxyBuilder
A Builder implementation responsible for generating proxy subclasses
of annotated classes (e.g., those annotated with @Service, @Component,
@Controller, etc.) during JetLeaf’s build phase.
The ProxyBuilder integrates with the build_runner toolchain to
transform .dart source files into corresponding .proxy.dart files
that contain interception-ready subclasses. These generated proxies
serve as runtime wrappers that enable JetLeaf’s method interception,
dependency injection, and lifecycle management mechanisms.
⚙️ How It Works
- File Filtering — Skips generation for any files inside the
Constant.GENERATED_DIR_NAMEdirectory to prevent recursive proxy generation. - Library Resolution — Uses the
BuildStep.resolverto resolve the Dart library represented by the input asset. - Annotation Discovery — Passes the library to the
ProxyGenerator, which identifies stereotype annotations such as
@Serviceor@Component. - Proxy Generation — For each discovered class, a proxy subclass
is emitted that wraps method calls in interception logic using
InterceptableandMethodInterceptorDispatcher. - Output Storage — The generated code is written to:
- The standard
.proxy.dartfile in the same directory, and - A project-wide generated directory (
_jetleaf/) for bootstrap inclusion.
- The standard
🧩 Example
Suppose you have a service class:
@Service()
class UserService {
String greet(String name) => 'Hello, $name';
}
After running dart run build_runner build, ProxyBuilder will
generate a file named:
lib/user_service.proxy.dart
containing:
final class $$UserService with Interceptable implements UserService, ClassGettable<UserService> {
final UserService delegate;
$$UserService(this.delegate);
@override
String greet(String name) async =>
this.when<String>(() async => delegate.greet(name), delegate, 'greet',
MethodArguments(positionalArgs: [name]));
}
📂 Output Organization
- Local proxy output:
lib/*.proxy.dart - Global generated proxy store:
${Constant.GENERATED_DIR_NAME}/<package>/<path>_proxy.dart
This dual output structure allows JetLeaf’s CLI (jl build) to include
proxies directly in the build bootstrap phase.
🧠 Notes
- Files inside
_jetleaf/are ignored to avoid recursive proxy generation. - SDK libraries (
dart:imports) are skipped during analysis. - The ProxyGenerator is stateless and can safely be reused across builds.
See also
- ProxyGenerator — the core generator that emits proxy class source
Interceptable— the mixin injected into generated proxy classesMethodInterceptorDispatcher— handles runtime interception flowConstant— defines_jetleafas the generated resource directory
Implementation
ProxyBuilder();