koin-core / org.koin.core / Koin

Koin

class Koin

Koin

Gather main features to use on Koin context

Author
Arnaud Giuliani

Constructors

<init>

Koin

Koin()

Properties

_logger

var _logger: Logger

_modules

val _modules: HashSet<Module>

_propertyRegistry

val _propertyRegistry: PropertyRegistry

_scopeRegistry

val _scopeRegistry: ScopeRegistry

Functions

bind

Get instance of primary type P and secondary type S (not for scoped instances)

fun <S, P> bind(parameters: ParametersDefinition? = null): S
fun <S> bind(primaryType: KClass<*>, secondaryType: KClass<*>, parameters: ParametersDefinition? = null): S

close

Close all resources from context

fun close(): Unit

createRootScope

fun createRootScope(): Unit

createScope

Create a Scope instance

fun createScope(scopeId: ScopeID, qualifier: Qualifier, source: Any? = null): Scope
fun <T> createScope(scopeId: ScopeID, source: Any? = null): Scope
fun <T> createScope(): Scope

declare

Declare a component definition from the given instance This result of declaring a single definition of type T, returning the given instance

fun <T : Any> declare(instance: T, qualifier: Qualifier? = null, secondaryTypes: List<KClass<*>> = emptyList(), override: Boolean = false): Unit

deleteProperty

Delete a property

fun deleteProperty(key: String): Unit

deleteScope

Delete a scope instance

fun deleteScope(scopeId: ScopeID): Unit

get

Get a Koin instance

fun <T> get(qualifier: Qualifier? = null, parameters: ParametersDefinition? = null): T
fun <T> get(clazz: KClass<*>, qualifier: Qualifier? = null, parameters: ParametersDefinition? = null): T

getAll

Get a all instance for given inferred class (in primary or secondary type)

fun <T : Any> getAll(): List<T>

getOrCreateScope

Get or Create a Scope instance

fun getOrCreateScope(scopeId: ScopeID, qualifier: Qualifier): Scope
fun <T> getOrCreateScope(scopeId: ScopeID): Scope

getOrNull

Get a Koin instance if available

fun <T> getOrNull(qualifier: Qualifier? = null, parameters: ParametersDefinition? = null): T?
fun <T> getOrNull(clazz: KClass<*>, qualifier: Qualifier? = null, parameters: ParametersDefinition? = null): T?

getProperty

Retrieve a property

fun getProperty(key: String, defaultValue: String): String
fun getProperty(key: String): String?

getScope

get a scope instance

fun getScope(scopeId: ScopeID): Scope

getScopeOrNull

get a scope instance

fun getScopeOrNull(scopeId: ScopeID): Scope?

inject

Lazy inject a Koin instance

fun <T> inject(qualifier: Qualifier? = null, parameters: ParametersDefinition? = null): Lazy<T>

injectOrNull

Lazy inject a Koin instance if available

fun <T> injectOrNull(qualifier: Qualifier? = null, parameters: ParametersDefinition? = null): Lazy<T?>

loadModules

fun loadModules(modules: List<Module>): Unit

setProperty

Save a property

fun setProperty(key: String, value: String): Unit

unloadModules

fun unloadModules(modules: List<Module>): Boolean

Extension Functions

getFloatProperty

Retrieve a float property

fun Koin.getFloatProperty(key: String, defaultValue: Float): Float
fun Koin.getFloatProperty(key: String): Float?

getIntProperty

Retrieve an int property

fun Koin.getIntProperty(key: String, defaultValue: Int): Int
fun Koin.getIntProperty(key: String): Int?

setFloatProperty

Save a float property

fun Koin.setFloatProperty(key: String, value: Float): Unit

setIntProperty

Save an int property

fun Koin.setIntProperty(key: String, value: Int): Unit