What would be an elegant way to create child graphs using ObjectGraph.plus()
with different modules according to the buildType?
I would like to ObjectGraph.plus(new ModuleA())
for buildType A and ObjectGraph.plus(new ModuleB())
for buildType B (with module B overriding module A in my case).
I'm already doing something similar with includes but I can't think of a way to do that with child graphs.
Asked
Active
Viewed 99 times
0

gdelente
- 776
- 8
- 14
1 Answers
3
Put a class in each build type folder which has a static method for listing modules.
// In src/release/java:
public class Modules {
public static Object[] list() {
return new Object[] {
new ModuleA()
};
}
}
// In src/debug/java:
public class Modules {
public static Object[] list() {
return new Object[] {
new ModuleA(),
new ModuleB()
};
}
}
Now when you call .create()
or .plus()
you can just delegate to these methods:
ObjectGraph.create(Modules.list());
You can see a real-world example of this at http://github.com/JakeWharton/u2020

Jake Wharton
- 75,598
- 23
- 223
- 230