Skip to content

Instantly share code, notes, and snippets.

@alejandro-rios
Last active September 14, 2019 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandro-rios/2a536b39eb691fab6a208e127c6979fa to your computer and use it in GitHub Desktop.
Save alejandro-rios/2a536b39eb691fab6a208e127c6979fa to your computer and use it in GitHub Desktop.
Basic Hello World with Dagger 2
class Info(val text: String)
// Module
@Module
class Bag {
@Provides
fun sayHelloDagger2(): Info {
return Info("Hello Dagger 2")
}
}
// Component
@Component(modules = [Bag::class])
interface MagicBox {
fun poke(app: MainActivity)
}
// MainActivity
class MainActivity : AppCompatActivity() {
// Retrieve Dependencies
@Inject
lateinit var info: Info
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
DaggerMagicBox.create().poke(this)
text_view.text = info.text
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment