Skip to main content
Version: 4.2

Start Koin Reference

Quick reference for starting Koin. For detailed guide see Core - Starting Koin.

Starting Methods

MethodUse Case
startKoin { }Standard apps - registers in GlobalContext
koinApplication { }Testing, SDKs - isolated instance
koinConfiguration { }Configuration for Compose, Ktor
startKoin<T>()Typed startup with Compiler Plugin

Basic Startup

startKoin {
modules(appModule)
}

Complete Configuration

startKoin {
logger(Level.INFO)
environmentProperties()
fileProperties()
properties(mapOf("env" to "production"))
modules(coreModule, networkModule)
lazyModules(analyticsModule)
createEagerInstances()
allowOverride(false)
}

Configuration Options

OptionDescription
logger()Set logging level and implementation
modules()Load modules immediately
lazyModules()Load modules in background
properties()Load properties from map
fileProperties()Load from koin.properties file
environmentProperties()Load from system/environment
createEagerInstances()Create all createdAtStart singletons
allowOverride()Enable/disable definition overriding

Typed Startup (Compiler Plugin)

Requires Koin Compiler Plugin and @KoinApplication:

@KoinApplication
class MyApp

// Start
startKoin<MyApp>()

// With configuration
startKoin<MyApp> {
printLogger()
}

Dynamic Module Management

// Load after startup
loadKoinModules(featureModule)

// Unload
unloadKoinModules(featureModule)

Stopping Koin

stopKoin()  // Global instance

// Isolated instance
koinApp.close()

Logging

LoggerPlatformDescription
EmptyLoggerAllNo logging (default)
PrintLoggerAllConsole output
AndroidLoggerAndroidLogcat
SLF4JLoggerJVMSLF4J
startKoin {
logger(Level.DEBUG) // or androidLogger() for Android
}

Properties

startKoin {
environmentProperties()
fileProperties() // koin.properties
properties(mapOf("key" to "value"))
}

// In module
single {
ApiClient(url = getProperty("server_url"))
}

Platform Examples

Android

class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
startKoin {
androidLogger()
androidContext(this@MainApplication)
modules(appModule)
}
}
}

Compose

@Composable
fun App() {
KoinApplication(
configuration = koinConfiguration { modules(appModule) }
) {
MainScreen()
}
}

Ktor

fun Application.module() {
install(Koin) {
slf4jLogger()
modules(appModule)
}
}

See Also