You never type barin foo.
ObjectGraph.create(new ExampleTestModule()).inject(main);
This line will display the fields mainthat are annotated @Injectand enter them. There is no recursive behavior.
Problem fix
Release step by step:
complete = false library = true Module. . , - , . , :
Error:(11, 8) error: No injectable members on BarImpl. Do you want to add an injectable constructor? required by providesBar(BarImpl) for ExampleTestModule.
BarImpl, :
public class BarImpl implements Bar {
@Inject
BarImpl(){
}
}
:
Error:(11, 8) error: Graph validation failed: You have these unused @Provider methods:
1. ExampleTestModule.providesBar()
Set library=true in your module to disable this check.
-, providesBar() . , bar foo . :
, providesFoo(), bar foo. , . foo @Injectable, foo, . , , bar, .
, @Inject foo main . ObjectGraph.get(Class<?>), main.
:
:
@Module(
injects = Main.class
)
public class ExampleTestModule {
@Provides
public Bar providesBar(BarImpl impl) {
return impl;
}
}
Main:
public class Main {
Foo foo;
@Inject
Main(Foo foo) {
this.foo = foo;
}
}
Foo:
public class Foo {
Bar bar;
@Inject
Foo(Bar bar){
this.bar = bar;
}
}
:
public interface Bar {
}
BarImpl:
public class BarImpl implements Bar {
@Inject
BarImpl(){
}
}
ApplicationTest:
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
public void testFoo() {
Main main = ObjectGraph.create(new ExampleTestModule()).get(Main.class);
assertNotNull(main.foo);
}
public void testFooBar() {
Main main = ObjectGraph.create(new ExampleTestModule()).get(Main.class);
assertNotNull(main.foo.bar);
}
}
:
library = true complete = false . .- . , . ,
private, . providesXXX , , bar BarImpl. , , , , ?