ProxyBuilder constructor

ProxyBuilder()

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

  1. File Filtering — Skips generation for any files inside the Constant.GENERATED_DIR_NAME directory to prevent recursive proxy generation.
  2. Library Resolution — Uses the BuildStep.resolver to resolve the Dart library represented by the input asset.
  3. Annotation Discovery — Passes the library to the ProxyGenerator, which identifies stereotype annotations such as @Service or @Component.
  4. Proxy Generation — For each discovered class, a proxy subclass is emitted that wraps method calls in interception logic using Interceptable and MethodInterceptorDispatcher.
  5. Output Storage — The generated code is written to:
    • The standard .proxy.dart file in the same directory, and
    • A project-wide generated directory (_jetleaf/) for bootstrap inclusion.

🧩 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 classes
  • MethodInterceptorDispatcher — handles runtime interception flow
  • Constant — defines _jetleaf as the generated resource directory

Implementation

ProxyBuilder();