Last active
September 14, 2019 21:36
-
-
Save alejandro-rios/2a536b39eb691fab6a208e127c6979fa to your computer and use it in GitHub Desktop.
Basic Hello World with Dagger 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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