I have a silly question to ask about Dagger 2. Because I want to be sure. I know that in compile time, Dagger generates code. But for the following code:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
//build main component along with core component
mainComponent = DaggerMainComponent
.builder()
.myModule(MyModule())
.coreComponent(DaggerCoreComponent.builder().build())
.build()
}
}
Does Dagger call the build() to build the component to draw the dependency graph at compile time or runtime? My understanding is it's at runtime, am I right?
If I am correct above, what about the following code ?:
@Module(subcomponents = MySubComponent.class)
abstract class MyModule {
...
}
My understanding is with this Dagger automatically detects whether the MySubComponent
is requested & if not it doesn't generate dependencies hosted in MySubComponent
. But does this process happen at runtime or compile time?