bindSingleton

inline fun <Type : Any> bindSingleton(singleton: Type)

Allows to bind a singleton to the chosen class.

Parameters

singleton

will be converted to a provider that always returns the same instance. If no type argument is passed, it will be bind to its own class.

Throws

if provider for the selected type is already defined.


inline fun <Type : Any> bindSingleton(provider: () -> Type)

Allows to bind a singleton to the chosen class.

Parameters

provider

inlined. Immediately invoked a single time. Its result will be registered as a singleton.

Throws

if provider for the selected type is already defined.


inline fun <Type : Any> bindSingleton(): Type

Automatically creates and registers an instance of Type with reflection. All required constructor parameters will be extracted from Context and must be present before calling this method.

Return

the constructed Type instance with injected dependencies.

Parameters

Type

reified type of the provided instance. This class must have a single constructor.

Throws

if any of the dependencies are missing.

ReflectionException

when unable to construct an instance.


fun <Type : Any> bindSingleton(vararg to: KClass<out Type>, singleton: Type)

Allows to bind a singleton instance to multiple classes in its hierarchy.

Parameters

to

list of interfaces and classes in the class hierarchy of the singleton. Any time any of the passed classes will be requested for injection, the selected singleton will be returned.

singleton

instance of class compatible with the passed types.

Throws

if provider for any of the selected types is already defined.


inline fun <Type : Any> bindSingleton(vararg to: KClass<out Type>, provider: () -> Type)

Allows to bind the result of the provider to multiple classes in its hierarchy.

Parameters

to

list of interfaces and classes in the class hierarchy of the provider. Any time any of the passed classes will be requested for injection, the selected provider will be returned.

provider

inlined. Immediately invoked a single time. Its result will be registered as a singleton.

Throws

if provider for any of the selected types is already defined.