47 lines
1.5 KiB
Kotlin
47 lines
1.5 KiB
Kotlin
package ru.pirogov.grapehealthchecker
|
|
|
|
import android.content.Context
|
|
import androidx.room.Room
|
|
import io.ktor.client.HttpClient
|
|
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
|
import io.ktor.serialization.kotlinx.json.json
|
|
import kotlinx.serialization.json.Json
|
|
import ru.pirogov.grapehealthchecker.data.AppDatabase
|
|
import ru.pirogov.grapehealthchecker.data.AppRepository
|
|
import ru.pirogov.grapehealthchecker.data.UserPreferencesRepository
|
|
import ru.pirogov.grapehealthchecker.data.WeatherRepository
|
|
import ru.pirogov.grapehealthchecker.utils.OnnxClassifier
|
|
|
|
class AppContainer(private val context: Context) {
|
|
|
|
// 1. Local Room DB Initialization
|
|
private val database: AppDatabase by lazy {
|
|
Room.databaseBuilder(context, AppDatabase::class.java, "photo_app.db").build()
|
|
}
|
|
|
|
// 2. HTTP Engine setup
|
|
private val httpClient by lazy {
|
|
HttpClient {
|
|
install(ContentNegotiation) {
|
|
json(Json { ignoreUnknownKeys = true })
|
|
}
|
|
}
|
|
}
|
|
|
|
// 3. Exposed Single Source Repositories
|
|
val appRepository: AppRepository by lazy {
|
|
AppRepository(database.appDao)
|
|
}
|
|
|
|
val weatherRepository: WeatherRepository by lazy {
|
|
WeatherRepository(database.appDao, httpClient)
|
|
}
|
|
|
|
val onnxClassifier: OnnxClassifier by lazy {
|
|
OnnxClassifier(context)
|
|
}
|
|
|
|
val userPreferencesRepository: UserPreferencesRepository by lazy {
|
|
UserPreferencesRepository(context)
|
|
}
|
|
} |