Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.18 KB | None | 0 0
  1. class ComicApplication : MultiDexApplication() {
  2.  
  3.     val component =
  4.         DaggerApplicationComponent.builder()
  5.             .testModule(TestModule())
  6.             .applicationModule(ApplicationModule(this))
  7.             .databaseModule(DatabaseModule())
  8.             .build()
  9.  
  10.  
  11.     @Inject lateinit var file: DbFile
  12.  
  13.     override fun onCreate() {
  14.         super.onCreate()
  15.         component.inject(this)
  16.         Toast.makeText(this, "Test ${file.path}", Toast.LENGTH_LONG).show()
  17.     }
  18.  
  19. }
  20.  
  21. class MainActivity : AppCompatActivity() {
  22.  
  23.     @Inject lateinit var file: DbFile
  24.  
  25.     override fun onCreate(savedInstanceState: Bundle?) {
  26.         super.onCreate(savedInstanceState)
  27.         setContentView(R.layout.activity_main)
  28.  
  29.         Toast.makeText(this, "Test ${file.path}", Toast.LENGTH_LONG).show()
  30. ...
  31. }
  32. }
  33.  
  34. @Component(modules = [ApplicationModule::class, DatabaseModule::class, TestModule::class])
  35. @Singleton
  36. interface ApplicationComponent {
  37.     fun inject(comicApplication: ComicApplication)
  38.     fun dbFile() : DbFile
  39.     fun database() : ComicDatabase
  40. }
  41.  
  42. @Module
  43. class TestModule {
  44.  
  45.     @Provides
  46.     fun file(): DbFile = DbFile(0,"123",0,0,0,0,"zzz")
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement