# HiltWorker

Artifact: [androidx.hilt:hilt-common](https://developer.android.com/jetpack/androidx/releases/hilt) [View Source](https://cs.android.com/search?q=file:androidx/hilt/work/HiltWorker.java+class:androidx.hilt.work.HiltWorker) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/hilt#1.0.0)

*** ** * ** ***


```
@Target(value = ElementType.TYPE)
@Retention(value = RetentionPolicy.CLASS)
@GeneratesRootInput
public annotation HiltWorker
```

<br />

*** ** * ** ***

A type annotation that identifies a `https://developer.android.com/reference/androidx/work/ListenableWorker`'s constructor for injection.

The `Worker` will be available for creation by the `https://developer.android.com/reference/androidx/hilt/work/HiltWorkerFactory` that should be set in `WorkManager`'s configuration via `https://developer.android.com/reference/androidx/work/Configuration.Builder#setWorkerFactory(androidx.work.WorkerFactory)`. The `HiltWorker` containing a constructor annotated with [AssistedInject](https://dagger.dev/api/latest/dagger/assisted/AssistedInject) will have its dependencies defined in the constructor parameters injected by Dagger's Hilt.

Example:

```
@HiltWorker
public class UploadWorker extends Worker {
    @AssistedInject
    public UploadWorker(@Assisted Context context, @Assisted WorkerParameters params,
            HttpClient httpClient) {
        // ...
    }
}
```

```
@HiltAndroidApp
public class MyApplication extends Application implements Configuration.Provider {
    @Inject HiltWorkerFactory workerFactory;

    @Override
    public Configuration getWorkManagerConfiguration() {
        return Configuration.Builder()
                .setWorkerFactory(workerFactory)
                .build();
    }
}
```

Only one constructor in the `Worker` must be annotated with [AssistedInject](https://dagger.dev/api/latest/dagger/assisted/AssistedInject). The constructor must define parameters for a [Assisted](https://dagger.dev/api/latest/dagger/assisted/Assisted)-annotated `Context` and a [Assisted](https://dagger.dev/api/latest/dagger/assisted/Assisted)-annotated `WorkerParameters` along with any other dependencies. Both the `Context` and `WorkerParameters` must not be a type param of `https://docs.oracle.com/javaee/7/api/javax/inject/Provider.html` nor [Lazy](https://dagger.dev/api/latest/dagger/Lazy) and must not be qualified.

Only dependencies available in the [SingletonComponent](https://dagger.dev/api/latest/dagger/hilt/components/SingletonComponent) can be injected into the `Worker`.