Skip to content

Dagger ‐ Injecting values at runtime by creating module

Devrath edited this page Oct 6, 2023 · 5 revisions

Observations

  • In projects sometimes we might need to pass the values dynamically, This means when we are creating the components(activity .. etc.) and not when dagger generates the code.
  • So appropriate variable as placeholders has to be set during the generation stage itself so that we can pass values for those variables.
  • In the output you can see that we had passed the dynamic value 20 from activity when the activity is being constructed.

Output

WatchBattery constructor is invoked !
Watch class constructor is invoked !
buildWatch method in watch class is invoked with capacity 20

Code

implementations

Modules

Components

Activity

Clone this wiki locally