I have a basic work manager
class BackgroundSyncWorker (
appContext: Context,
workerParams: WorkerParameters
): Worker(appContext, workerParams) {
override fun doWork(): Result {
return Result.success()
}
}
And I want to inject my repository into this to do some work in my database. I've set Koin up correctly but can't seem to find a way of how to inject my dependency into the Worker. I've tried inheriting the KoinComponent and trying to do it using that, but by inject()
doesn't exist, but there's two by inject
methods that I can't find how to use. There doesn't seem to be any information on how to inject into managers, although there's a few for using dagger.
This does actually work, I was just using var
instead of val.
class BackgroundSyncWorker (
appContext: Context,
workerParams: WorkerParameters
): Worker(appContext, workerParams), KoinComponent {
val dataSyncRepository : DataSyncRepositoryImpl by inject()
override fun doWork(): Result {
return Result.success()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With