DI

interface DI : DIAware

KOtlin DEpendency INjection.

To construct a DI instance, simply use it's block constructor and define your bindings in it :

val di = DI {
bind<Dice>() with factory { sides: Int -> RandomDice(sides) }
bind<DataSource>() with singleton { SqliteDS.open("path/to/file") }
bind<Random>() with provider { SecureRandom() }
constant("answer") with "forty-two"
}

Types

BindBuilder
Link copied to clipboard
interface BindBuilder<C : Any>

Base builder DSL interface that allows to define scoped and context bindings.

Builder
Link copied to clipboard
interface Builder : DI.BindBuilder<Any> , DI.BindBuilder.WithScope<Any>

Allows for the DSL inside the block argument of the constructor of DI and DI.Module.

Companion
Link copied to clipboard
object Companion
DependencyLoopException
Link copied to clipboard
class DependencyLoopException : RuntimeException

Exception thrown when there is a dependency loop.

DIDsl
Link copied to clipboard
annotation class DIDsl

Defines a di DSL function

Key
Link copied to clipboard
data class Key<in C : Any, in A, out T : Any>(contextType: TypeToken<in C>, argType: TypeToken<in A>, type: TypeToken<out T>, tag: Any?)

In DI, each DIBinding is bound to a Key. A Key holds all information necessary to retrieve a factory (and therefore an instance).

MainBuilder
Link copied to clipboard
interface MainBuilder : DI.Builder

Builder to create a DI object.

Module
Link copied to clipboard
data class Module(name: String, allowSilentOverride: Boolean, prefix: String, init: DI.Builder.() -> Unit)

A module is constructed the same way as in DI is:

NoResultException
Link copied to clipboard
class NoResultException(search: SearchSpecs, message: String) : RuntimeException

Exception thrown when searching for bindings and none could be found.

NotFoundException
Link copied to clipboard
class NotFoundException(key: DI.Key<*, *, *>, message: String) : RuntimeException

Exception thrown when asked for a dependency that cannot be found.

OverridingException
Link copied to clipboard
class OverridingException(message: String) : RuntimeException

Exception thrown when there is an overriding error.

Properties

container
Link copied to clipboard
abstract val container: DIContainer

Every methods eventually ends up to a call to this container.

di
Link copied to clipboard
open override val di: DI

A DI Aware class must be within reach of a DI object.

diContext
Link copied to clipboard
open val diContext: DIContext<*>

A DI Aware class can define a context that is for all retrieval by overriding this property.

diTrigger
Link copied to clipboard
open val diTrigger: DITrigger?

Trigger to use that define when the retrieval will be done.

Inheritors

LateInitDI
Link copied to clipboard
LazyDI
Link copied to clipboard