-
Notifications
You must be signed in to change notification settings - Fork 115
DI Graph Validation
Stéphane Nicolas edited this page Oct 20, 2019
·
4 revisions
During runtime, Toothpick will build the graph required to perform injections. It involves:
- creating the scope tree;
- installing bindings via modules;
- creating dynamic bindings via factories created during annotation processing & discovered at runtime;
- transitively creating all dependencies;
- assigning these dependencies to the dependents, starting at a given entry point.
And this can fail !
For instance, an entry point can inject a dependency for which TP has no binding, or a dependency can require a given scope annotation that is not present in the scope tree.
Some DI framework approach this problem by enforcing a graph validation at compile time, like Dagger 2.
With Toothpick, it's also possible to automate the DI graph validation, but at test-time. In the sample for toothpick, we demonstrate how to perform this validation using simple unit tests. They don't require robolectric (some of your tests might need robolectric or need to be instrumented, depending on your code).