TangleWorkerFactory
A WorkerFactory for Tangle. This factory references the Dagger dependency graph via the TangleGraph singleton, and uses it to generate injected ListenableWorker instances.
Since
0.12.0
Samples
import androidx.work.Configuration
import tangle.inject.TangleGraph
import tangle.inject.test.utils.Application
import tangle.inject.test.utils.DaggerAppComponent
import tangle.inject.test.utils.MyApplicationComponent
import tangle.inject.test.utils.Sample
import tangle.work.TangleWorkerFactory
import javax.inject.Inject
fun main() {
//sampleStart
class MyApplication : Application(), Configuration.Provider {
@Inject lateinit var workerFactory: TangleWorkerFactory
override fun onCreate() {
super.onCreate()
val myAppComponent = DaggerAppComponent.factory()
.create(this)
TangleGraph.add(myAppComponent)
// inject your application class after initializing TangleGraph
(myAppComponent as MyApplicationComponent).inject(this)
}
// now the WorkManager instances will use TangleWorkerFactory
override fun getWorkManagerConfiguration(): Configuration {
return Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()
}
}
//sampleEnd
}
Constructors
Functions
Link copied to clipboard
open override fun createWorker(appContext: Context, workerClassName: String, workerParameters: WorkerParameters): ListenableWorker?
Content copied to clipboard
Link copied to clipboard
fun createWorkerWithDefaultFallback(@NonNull appContext: Context, @NonNull workerClassName: String, @NonNull workerParameters: WorkerParameters): ListenableWorker?
Content copied to clipboard