mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 03:17:03 +05:30
Create a rudimentary DI container for Room
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
3d8935dc2b
commit
644a8a6110
3 changed files with 31 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
package="dev.msfjarvis.todo">
|
||||
|
||||
<application
|
||||
android:name=".Application"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
|
11
app/src/main/java/dev/msfjarvis/todo/Application.kt
Normal file
11
app/src/main/java/dev/msfjarvis/todo/Application.kt
Normal file
|
@ -0,0 +1,11 @@
|
|||
package dev.msfjarvis.todo
|
||||
|
||||
import android.app.Application
|
||||
import dev.msfjarvis.todo.di.Graph
|
||||
|
||||
class Application : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
Graph.provide(this)
|
||||
}
|
||||
}
|
19
app/src/main/java/dev/msfjarvis/todo/di/Graph.kt
Normal file
19
app/src/main/java/dev/msfjarvis/todo/di/Graph.kt
Normal file
|
@ -0,0 +1,19 @@
|
|||
package dev.msfjarvis.todo.di
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import dev.msfjarvis.todo.data.source.TodoDatabase
|
||||
|
||||
/**
|
||||
* Rudimentary DI container to initialize singletons, will be switched to Hilt when architecture becomes
|
||||
* a focus again.
|
||||
*/
|
||||
object Graph {
|
||||
|
||||
lateinit var database: TodoDatabase
|
||||
|
||||
fun provide(context: Context) {
|
||||
database = Room.databaseBuilder(context, TodoDatabase::class.java, "data.db")
|
||||
.fallbackToDestructiveMigration().build()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue