inject
Performs member/field injection upon target using its bound scope.
Be sure to call TangleGraph.add with your scope's Component or Subcomponent before calling this function.
Since
0.13.0
Samples
import tangle.inject.TangleGraph
import tangle.inject.TangleScope
import tangle.inject.test.utils.AppScope
import tangle.inject.test.utils.Application
import tangle.inject.test.utils.DaggerAppComponent
import tangle.inject.test.utils.MyLogger
import tangle.inject.test.utils.Sample
import tangle.inject.test.utils.Timber
import javax.inject.Inject
fun main() {
//sampleStart
@TangleScope(AppScope::class) // dependencies will come from the AppScope
class MyApplication : Application() {
@Inject lateinit var logger: MyLogger
override fun onCreate() {
super.onCreate()
val appComponent = DaggerAppComponent.factory()
.create(this)
// connect the app's Dagger graph to Tangle
TangleGraph.add(appComponent)
// inject MyLogger using Dagger/Tangle
TangleGraph.inject(this)
// logger is not initialized and safe to use
Timber.plant(logger)
}
}
//sampleEnd
}