Google is committed to advancing racial equity for Black communities. See how.


public abstract @interface WorkerInject
implements Annotation

Identifies a ListenableWorker's constructor for injection.

Similar to Inject, a Worker containing a constructor annotated with WorkerInject will have its dependencies defined in the constructor parameters injected by Dagger's Hilt. The Worker will be available for creation by the HiltWorkerFactory that should be set in WorkManager's configuration via Configuration.Builder.setWorkerFactory(


 public class UploadWorker extends Worker {
     public UploadWorker(@Assisted Context context, @Assisted WorkerParameters params,
             HttpClient httpClient) {
         // ...
 public class MyApplication extends Application implements Configuration.Provider {
     @Inject HiltWorkerFactory workerFactory;

     public Configuration getWorkManagerConfiguration() {
         return Configuration.Builder()

Only one constructor in the Worker must be annotated with WorkerInject. The constructor must define parameters for a Assisted-annotated Context and a Assisted-annotated WorkerParameters along with any other dependencies. Both the Context and WorkerParameters must not be a type param of Provider nor Lazy and must not be qualified.

Only dependencies available in the ApplicationComponent can be injected into the Worker.


Inherited methods