liminal
11/01/2018, 3:40 PM.addCallback(object : RoomDatabase.Callback() { override fun onCreate(db: SupportSQLiteDatabase) ... }
. So by the time I needed to use the data inserted, it was there. With Koin, my DB is declared as a bean
and it gets created lazily so first time I access the database, 0 items is returned, coming back to that screen again renders all of the items. I tried initializing the DB in my Application.onCreate() but the the database's onCreate() does not get called. Any ideas what can be done? My thinking is I need to somehow create the database and its data before it's first accessed (as opposed to how Koin is designed to access dependencies lazily when they are needed by that particular screen). I doubt this part is relevant but I use Google Arch Paging component to load data.dknapp
11/01/2018, 4:01 PMdknapp
11/01/2018, 4:02 PMsingle<Service>(createOnStart=true) { TestServiceImp() }
liminal
11/01/2018, 4:03 PMliminal
11/01/2018, 6:41 PMdknapp
11/01/2018, 6:48 PMliminal
11/01/2018, 7:31 PMval dbModule = module(createOnStart=true) {
single { MyDatabase.getInstance(androidContext()) }
single { get<MyDatabase>().myDao() }
}
val otherModule = module {
single { MyRepositoryImpl(get(), get()) as MyRepository }
single { MyKeyedDataSource(get()) }
single { MyPagingDataSourceFactory(get()) }
single { MyViewModelFactory(get()) }
}
liminal
11/01/2018, 7:32 PMstartKoin(this, listOf(dbModule, otherModule))
dknapp
11/01/2018, 8:03 PMliminal
11/01/2018, 8:13 PMval dbModule = module {
// eager creation for this definition
single(createOnStart=true) { MyDatabase.getInstance(androidContext()) }
single(createOnStart=true) { get<MyDatabase>().myDao() }
}
liminal
11/01/2018, 8:14 PMliminal
11/01/2018, 8:48 PMliminal
11/01/2018, 9:15 PM