Inject into Workers (androidx.WorkManager API)
See original GitHub issueHi,
from latest Google I/O you just presented the new androidx.work.Worker
class, part of the new WorkManager API.
Since the Worker
class is created by the framework (we only pass the Worker class type to the WorkManager
), how can we @inject fields into the Worker ?
Do you intend to add a new AndroidInjection.inject() function that takes a worker as argument ?
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:85
- Comments:43 (1 by maintainers)
Top Results From Across the Web
Inject into Workers (androidx.WorkManager API) - Medium
Step 1: Create AndroidWorkerInjection.class Responsible for injecting dependencies into [WorkManager API](https://developer.android.com/topic/ ...
Read more >Getting started with WorkManager - Android Developers
To get started using WorkManager, first import the library into your Android project. Add the following dependencies to your app's build.gradle file:.
Read more >Dagger 2 setup with WorkManager - ProAndroidDev
Setup our existing code base with AssistedInject is simple. Annotate Worker class with @AssistedInject . Any parameters that we want to create with...
Read more >How to inject Worker class? - android - Stack Overflow
When I try to inject updater worker to main activity, I get this error: Dagger does not support injecting @AssistedInject type, .workmanager.
Read more >Android WorkManager Worker can not be injected using ...
Add kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha01' to your app's build.gradle and it should work.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We hope to have something soon. It likely will be in a new artifact (
dagger-android-work
), plus support for@ContributesAndroidInjector
.I know this is the wrong repo for this comment, but I wonder aloud why they couldn’t have created a WorkerFactory class similar to ViewModelProvider.Factory for defining how to create Worker objects. Or something. I just really don’t understand why Android framework classes can never have useful public constructors.