https://kotlinlang.org logo
#dagger
Title
# dagger
d

dave08

01/18/2022, 4:10 PM
Why doesn't Hilt provide a
@WorkComponent
for WorkManager workers? Is there a way to make my own? Or is it intended, and there's something different to do for workers?
c

Colton Idle

01/18/2022, 5:20 PM
I don't use workmanager, but no one from the workmanager/hilt team is here, so I doubt you will get an answer to your question. I'd file a bug/feature request. Also, there seems to be some sort of integration available in the docs: https://developer.android.com/training/dependency-injection/hilt-jetpack#workmanager
f

FunkyMuse

01/18/2022, 5:55 PM
Basically WorkManager has assisted injected constructor, you can put there dependencies that live in your custom scope
1
t

trevjones

01/19/2022, 3:16 AM
WorkerFactoryModule
is install to Singleton and the `androidx.work.Configuration`` is used to initialize inside of a double check lock to ensure a single instance of the factory is created. Which should mean that the only safe scope to depend on is
Singleton
or unscoped. Scoping the worker itself seems bad given each invocation is going to get its own instance of
WorkerParameters
d

dave08

01/19/2022, 4:07 AM
Yeah, but all worker dependencies are going to live throughout application life... So if multiple dependencies depend on one other, it's either create ot twice, or make it live during the application's lifetime...
49 Views