TangleScope

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class TangleScope(scope: KClass<*>)

Annotates a member-injected class to indicate the scope which will provide its dependencies.

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
}

Constructors

Link copied to clipboard
fun TangleScope(scope: KClass<*>)

Properties

Link copied to clipboard
val scope: KClass<*>

The scope from which to pull the annotated class's dependencies.

Sources

Link copied to clipboard