Matthew Laser
10/11/2023, 8:06 PMcurioustechizen
10/12/2023, 3:58 AMascii
10/12/2023, 4:05 AMsingle { WorkManager.getInstance(androidContext()) }
. You can inject
the instance and you still retain default androidx startup capabilities.
Indeed, docs for koin-androidx-workmanager
are confusing and don't reveal to me what I'd gain if I use it.curioustechizen
10/12/2023, 6:42 AMcurioustechizen
10/12/2023, 6:51 AMWorkManager.getInstance()
is just to get an instance of WorkManager. Koin's WM integration allows you to declare and inject Worker
instances, not just the WorkManager
instance. It allows you to do this:
worker {
FirmwareUpdateWorker(
bleRepository = get(),
appContext = get(),
firmwareUpdateConfig = get(),
params = it.get()
)
}
Here. FirmwareUpdateWorker
sub-classes CoroutineWorker
and it has constructor parameters that Koin helps you inject.curioustechizen
10/12/2023, 6:52 AMval firmwareUpdateWorkRequest = OneTimeWorkRequestBuilder<FirmwareUpdateWorker> ()
Koin's workerManagerFactory
and the above worker
DSL work together to obtain the correct instance of the Worker.curioustechizen
10/12/2023, 6:53 AMascii
10/12/2023, 7:38 AMgetKoin().inject
inside the worker.