inject_compile_generator 0.9.0
inject_compile_generator: ^0.9.0 copied to clipboard
Dev-time dependency for package:inject.
Compile-Time Dependency Injection Code Generator #
This package provides the build_runner code generator for inject_compile.
It processes your dependency injection annotations to generate the boilerplate
graph wiring at build time.
Getting Started #
Add inject_compile_generator to your dev_dependencies alongside build_runner,
and inject_compile to your regular dependencies:
dependencies:
inject_compile: ^0.9.0
dev_dependencies:
build_runner: ^2.4.0
inject_compile_generator: ^0.9.0
Running the Generator #
To generate the DI files, run the build runner command in your project directory:
dart run build_runner build
To continuously watch files and regenerate them during development:
dart run build_runner watch
How It Works #
The code generator runs in two phases to optimize build speed:
- Summary Extraction: First, a
SummaryBuilderextracts metadata from@provide,@module, and@injectorannotations into lightweight.inject.summarycache files. - Code Generation: Next, an
InjectBuilderreads these summaries, resolves the complete dependency tree, validates it for issues like circular dependencies, and outputs concrete.inject.dartimplementations usingcode_builder.
Since validation occurs at compile-time, errors such as missing dependencies or dependency cycles are reported directly during the build process, preventing runtime exceptions.
Next Steps #
- To learn how to define your object graph, visit the
inject_compileannotations library. - For complete samples, see the workspace examples.