I'm new to android development, i need to inject WorkManager for using kodein but i don't know where to start it
this is how to inject activities
class MyActivity : Activity(), KodeinAware {
override val kodein by kodein()
val ds: DataSource by instance()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ds.connect()
/* ... */
}
}
this is my worker i need to get the instance of Appdatabase for using kodein but it didn't work for me
class MyWorker(context: Context, params: WorkerParameters) :
CoroutineWorker(context, params), KodeinAware {
override val kodein by kodein()
private val db: AppDatabase by instance()
override suspend fun doWork(): Result = withContext(IO) {
try {
//do the work
Result.success()
} catch (e: Exception) {
Result.retry()
}
}
}
Binding the AppDatabase
class AppBase : Application(), KodeinAware {
override val kodein = Kodein.lazy {
import(androidXModule(this@AppBase))
bind() from singleton { AppDatabase.getInstance(instance())}
}
}