There is a case that I need to construct my dependency before it is provided to the classes injecting it. Is it possible to create an instance of this dependency already in the module's constuctor?
This dependency is a scoped dependency, so I am worried if doing the following will lead to a leakage.
HERE IS WHAT I WANT TO DO:
@Module(
injects = { Controller.class},
complete = false,
addsTo = InitModule.class
)
public class SubModule {
public ScopedDependency dep;
public SubModule() {
this.dep = new ScopedDependency();
}
@Provides
@Singleton
public ScopedDependency provideScopedDependency() {
return dep;
}
}
INSTEAD OF THIS:
@Module(
injects = { Controller.class },
complete = false,
addsTo = InitModule.class
)
public class SubModule {
@Provides
@Singleton
public ScopedDependency provideScopedDependency() {
return new ScopedDependency();
}
}
When I decide to release the scopedGraph (scopedGraph = null), will I leak the ScopedDependency instance if I use the first approach?
Using dagger 1.2.2
There is a case that I need to construct my dependency before it is provided to the classes injecting it. Is it possible to create an instance of this dependency already in the module's constuctor? This dependency is a scoped dependency, so I am worried if doing the following will lead to a leakage.
HERE IS WHAT I WANT TO DO:
INSTEAD OF THIS:
When I decide to release the scopedGraph (
scopedGraph = null
), will I leak the ScopedDependency instance if I use the first approach?