MainBuilder

Builder to create a DI object.

Properties

Link copied to clipboard

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

Link copied to clipboard
abstract val contextType: TypeToken<Any>

The context type that will be used by all bindings that are defined in this DSL context.

Link copied to clipboard
abstract val explicitContext: Boolean
Link copied to clipboard

The external source is repsonsible for fetching / creating a value when DI cannot find a matching binding.

Link copied to clipboard

If true, NotFoundException thrown will contain the list of all the bindings available.

Link copied to clipboard

If true, exceptions thrown will contain qualified names.

Link copied to clipboard
abstract val scope: Scope<Any>

The scope that will be used by all bindings that are defined in this DSL context.

Functions

Link copied to clipboard
abstract fun <T : Any> AddBindInSet(tag: Any? = null, overrides: Boolean? = null, binding: DIBinding<*, *, T>)

Attaches multiple bindings in a Set binding of a given type with a given tag.

Link copied to clipboard
inline fun <T : Any> DI.Builder.addInBindSet(tag: Any? = null, overrides: Boolean? = null, creator: () -> DIBinding<*, *, T>)

Defines that the binding will be saved in a set binding.

Link copied to clipboard
abstract fun Bind(tag: Any? = null, overrides: Boolean? = null): DI.Builder.DirectBinder

Starts a direct binding with a given tag. A direct bind does not define the type to be bound, the type will be defined according to the bound factory.

abstract fun <T : Any> Bind(tag: Any? = null, overrides: Boolean? = null, binding: DIBinding<*, *, T>)

Attaches the binding of a given type with a given tag.

abstract fun <T : Any> Bind(type: TypeToken<out T>, tag: Any? = null, overrides: Boolean? = null): DI.Builder.TypeBinder<T>

Starts the binding of a given type with a given tag.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bind(tag: Any? = null, overrides: Boolean? = null): DI.Builder.TypeBinder<T>

Starts the binding of a given type with a given tag.

inline fun <T : Any> DI.Builder.bind(tag: Any? = null, overrides: Boolean? = null, noinline createBinding: () -> DIBinding<*, *, T>)

Attaches a binding to the DI container

Link copied to clipboard
inline fun <A : Any, T : Any> DI.Builder.bindArgSet(tag: Any? = null, overrides: Boolean? = null)

Creates a set: multiple bindings can be added in this set.

inline fun <A : Any, T : Any> DI.Builder.bindArgSet(tag: Any? = null, overrides: Boolean? = null, noinline creator: DI.Builder.ArgSetBinder<A, T>.() -> Unit)

Creates a set and add multiple bindings to it.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bindConstant(tag: Any, overrides: Boolean? = null, creator: () -> T)

Binds a constant provider: will always return the given instance.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bindEagerSingleton(tag: Any? = null, overrides: Boolean? = null, noinline creator: DirectDI.() -> T)

Binds an eager singleton: will create an instance as soon as kodein is ready (all bindings are set) and will always return this instance.

Link copied to clipboard
inline fun <A : Any, T : Any> DI.Builder.bindFactory(tag: Any? = null, overrides: Boolean? = null, noinline creator: DirectDI.(A) -> T)

Binds a factory: each time an instance is needed, the function creator function will be called.

Link copied to clipboard
abstract fun <A : Any, T : Any> BindInArgSet(tag: Any? = null, overrides: Boolean? = null, argType: TypeToken<in A>, type: TypeToken<out T>, creator: DI.Builder.ArgSetBinder<A, T>.() -> Unit)

Creates a Set binding of a given type with a given tag and attaches multiple bindings to it.

Link copied to clipboard
abstract fun <T : Any> BindInSet(tag: Any? = null, overrides: Boolean? = null, type: TypeToken<out T>, creator: DI.Builder.SetBinder<T>.() -> Unit)

Creates a Set binding of a given type with a given tag and attaches multiple bindings to it.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bindInstance(tag: Any? = null, overrides: Boolean? = null, creator: () -> T)

Binds an instance provider: will always return the given instance.

Link copied to clipboard
inline fun <A : Any, T : Any> DI.Builder.bindMultiton(tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true, noinline creator: DirectDI.(A) -> T)

Binds a multiton: will create an instance on first request and will subsequently always return the same instance.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bindProvider(tag: Any? = null, overrides: Boolean? = null, noinline creator: DirectDI.() -> T)

Creates a factory: each time an instance is needed, the function creator function will be called.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bindProviderOf(noinline constructor: () -> T, tag: Any? = null, overrides: Boolean? = null)

Creates a factory: each time an instance is needed, the function constructor function will be called.

inline fun <T : Any, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> DI.Builder.bindProviderOf(noinline constructor: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1> DI.Builder.bindProviderOf(noinline constructor: (P1) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1, P2> DI.Builder.bindProviderOf(noinline constructor: (P1, P2) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1, P2, P3> DI.Builder.bindProviderOf(noinline constructor: (P1, P2, P3) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1, P2, P3, P4> DI.Builder.bindProviderOf(noinline constructor: (P1, P2, P3, P4) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1, P2, P3, P4, P5> DI.Builder.bindProviderOf(noinline constructor: (P1, P2, P3, P4, P5) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1, P2, P3, P4, P5, P6> DI.Builder.bindProviderOf(noinline constructor: (P1, P2, P3, P4, P5, P6) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1, P2, P3, P4, P5, P6, P7> DI.Builder.bindProviderOf(noinline constructor: (P1, P2, P3, P4, P5, P6, P7) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1, P2, P3, P4, P5, P6, P7, P8> DI.Builder.bindProviderOf(noinline constructor: (P1, P2, P3, P4, P5, P6, P7, P8) -> T, tag: Any? = null, overrides: Boolean? = null)
inline fun <T : Any, P1, P2, P3, P4, P5, P6, P7, P8, P9> DI.Builder.bindProviderOf(noinline constructor: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> T, tag: Any? = null, overrides: Boolean? = null)
Link copied to clipboard
abstract fun <T : Any> BindSet(tag: Any? = null, overrides: Boolean? = null, binding: DIBinding<*, *, T>)

Attaches the binding of a given type with a given tag.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bindSet(tag: Any? = null, overrides: Boolean? = null)

Creates a set: multiple bindings can be added in this set.

inline fun <T : Any> DI.Builder.bindSet(tag: Any? = null, overrides: Boolean? = null, noinline creator: DI.Builder.SetBinder<T>.() -> Unit)

Creates a set and add multiple bindings to it.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bindSingleton(tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true, noinline creator: DirectDI.() -> T)

Binds a singleton: will create an instance on first request and will subsequently always return the same instance.

Link copied to clipboard
inline fun <T : Any> DI.Builder.bindSingletonOf(noinline constructor: () -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)

Binds a singleton: will create an instance on first request and will subsequently always return the same instance.

inline fun <T : Any, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1> DI.Builder.bindSingletonOf(noinline constructor: (P1) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1, P2> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1, P2, P3> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2, P3) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1, P2, P3, P4> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2, P3, P4) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1, P2, P3, P4, P5> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2, P3, P4, P5) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1, P2, P3, P4, P5, P6> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2, P3, P4, P5, P6) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1, P2, P3, P4, P5, P6, P7> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2, P3, P4, P5, P6, P7) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1, P2, P3, P4, P5, P6, P7, P8> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2, P3, P4, P5, P6, P7, P8) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
inline fun <T : Any, P1, P2, P3, P4, P5, P6, P7, P8, P9> DI.Builder.bindSingletonOf(noinline constructor: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> T, tag: Any? = null, overrides: Boolean? = null, sync: Boolean = true)
Link copied to clipboard
abstract fun constant(tag: Any, overrides: Boolean? = null): DI.Builder.ConstantBinder

Starts a constant binding.

Link copied to clipboard

Used to define bindings with a context: bind<MyType>() with contexted<MyContext>().provider { /*...*/ }

Link copied to clipboard
abstract fun <T : Any> Delegate(type: TypeToken<out T>, tag: Any? = null, overrides: Boolean? = null): DI.Builder.DelegateBinder<T>

Create a delegate binding to a given bound type with a given tag.

Link copied to clipboard
inline fun <T : Any> DI.Builder.delegate(tag: Any? = null, overrides: Boolean? = null): DI.Builder.DelegateBinder<T>

Delegate the targeted type to a new binding type

Link copied to clipboard
inline fun <T : Any> DI.Builder.eagerSingleton(noinline creator: NoArgBindingDI<Any>.() -> T): EagerSingleton<T>

Creates an eager singleton: will create an instance as soon as kodein is ready (all bindings are set) and will always return this instance.

Link copied to clipboard
abstract fun extend(di: DI, allowOverride: Boolean = false, copy: Copy = Copy.NonCached)
abstract fun extend(directDI: DirectDI, allowOverride: Boolean = false, copy: Copy = Copy.NonCached)

Imports all bindings defined in the given DI into this builder.

Link copied to clipboard
inline fun <C : Any, A : Any, T : Any> DI.BindBuilder<C>.factory(noinline creator: BindingDI<C>.(A) -> T): Factory<C, A, T>

Creates a factory: each time an instance is needed, the function creator function will be called.

Link copied to clipboard
abstract fun import(module: DI.Module, allowOverride: Boolean = false)

Imports all bindings defined in the given DI.Module into this builder's definition.

Link copied to clipboard
abstract fun importAll(vararg modules: DI.Module, allowOverride: Boolean = false)
abstract fun importAll(modules: Iterable<DI.Module>, allowOverride: Boolean = false)

Imports all bindings defined in the given DI.Modules into this builder's definition.

Link copied to clipboard
abstract fun importOnce(module: DI.Module, allowOverride: Boolean = false)

Like import but checks that will only import each module once.

Link copied to clipboard
abstract fun <A : Any, T : Any> InBindArgSet(tag: Any? = null, overrides: Boolean? = null, argType: TypeToken<in A>, type: TypeToken<out T>, creator: DI.Builder.ArgSetBinder<A, T>.() -> Unit)

Attaches multiple bindings in a Set binding of a given type with a given tag.

Link copied to clipboard
abstract fun <T : Any> InBindSet(tag: Any? = null, overrides: Boolean? = null, type: TypeToken<out T>, creator: DI.Builder.SetBinder<T>.() -> Unit)

Attaches multiple bindings in a Set binding of a given type with a given tag.

Link copied to clipboard
inline fun <T : Any> DI.Builder.inBindSet(tag: Any? = null, overrides: Boolean? = null, noinline creator: DI.Builder.SetBinder<T>.() -> Unit)

Add multiple bindings in an existing set

Link copied to clipboard
inline fun <T : Any> DI.Builder.inSet(tag: Any? = null, overrides: Boolean? = null, creator: () -> DIBinding<*, *, T>)

Defines that the binding will be saved in a set binding.

Link copied to clipboard
inline fun <T : Any> DI.Builder.instance(instance: T): InstanceBinding<T>

Creates an instance provider: will always return the given instance.

Link copied to clipboard
inline fun <C : Any, A : Any, T : Any> DI.BindBuilder.WithScope<C>.multiton(ref: RefMaker? = null, sync: Boolean = true, noinline creator: BindingDI<C>.(A) -> T): Multiton<C, A, T>

Creates a multiton: will create an instance on first request for each different argument and will subsequently always return the same instance for the same argument.

Link copied to clipboard
abstract fun onReady(cb: DirectDI.() -> Unit)

Adds a callback that will be called once the DI object is configured and instantiated.

Link copied to clipboard
inline fun <C : Any, T : Any> DI.BindBuilder<C>.provider(noinline creator: NoArgBindingDI<C>.() -> T): Provider<C, T>

Creates a factory: each time an instance is needed, the function creator function will be called.

Link copied to clipboard
inline fun <S : Any> DI.Builder.registerContextFinder(noinline t: DirectDI.() -> S)
Link copied to clipboard
abstract fun RegisterContextTranslator(translator: ContextTranslator<*, *>)
Link copied to clipboard
inline fun <C : Any, S : Any> DI.Builder.registerContextTranslator(noinline t: DirectDI.(C) -> S?)
Link copied to clipboard

Used to define bindings with a scope: bind<MyType>() with scoped(myScope).singleton { /*...*/ }

Link copied to clipboard
inline fun <C : Any, T : Any> DI.BindBuilder.WithScope<C>.singleton(ref: RefMaker? = null, sync: Boolean = true, noinline creator: NoArgBindingDI<C>.() -> T): Singleton<C, T>

Creates a singleton: will create an instance on first request and will subsequently always return the same instance.