2019-04-11 20:01:49 +02:00
|
|
|
package com.topjohnwu.magisk.di
|
|
|
|
|
2019-05-06 20:12:31 +02:00
|
|
|
import android.content.Context
|
|
|
|
import androidx.room.Room
|
2019-04-17 18:27:03 +02:00
|
|
|
import com.topjohnwu.magisk.App
|
2019-05-06 20:12:31 +02:00
|
|
|
import com.topjohnwu.magisk.data.database.*
|
2019-04-11 20:01:49 +02:00
|
|
|
import org.koin.dsl.module
|
|
|
|
|
|
|
|
|
2019-04-17 18:27:03 +02:00
|
|
|
val databaseModule = module {
|
2019-04-27 11:27:42 +02:00
|
|
|
single { MagiskDB(get<App>().protectedContext) }
|
2019-05-06 20:12:31 +02:00
|
|
|
single { createDatabase(get()) }
|
|
|
|
single { LogDao() }
|
|
|
|
single { PolicyDao(get()) }
|
|
|
|
single { SettingsDao() }
|
|
|
|
single { StringsDao() }
|
|
|
|
single { createRepositoryDao(get()) }
|
2019-04-17 18:27:03 +02:00
|
|
|
}
|
2019-05-06 20:12:31 +02:00
|
|
|
|
|
|
|
fun createDatabase(context: Context): AppDatabase =
|
|
|
|
Room.databaseBuilder(context, AppDatabase::class.java, AppDatabase.NAME).build()
|
|
|
|
|
|
|
|
fun createRepositoryDao(db: AppDatabase) = db.repoDao()
|