theimpulson
05/04/2026, 8:04 AMDmitry Stakhov
05/04/2026, 8:17 AM@Single
class MyClass(context: Context)
And pass the context instance while initializing koin
onCreate() {
startKoin {
androidContext(context)
modules(koinModule)
}
}
You can get more details in the official documentation
https://insert-koin.io/docs/reference/koin-android/start/theimpulson
05/04/2026, 8:20 AMKoinApplication(configuration = koinConfiguration<KoinApp>()) {}theimpulson
05/04/2026, 8:21 AMDmitry Stakhov
05/04/2026, 8:26 AMtheimpulson
05/04/2026, 8:32 AMtheimpulson
05/04/2026, 8:34 AMpackage net.newpipe.app.di
import com.russhwolf.settings.Settings
import org.koin.core.annotation.Configuration
import org.koin.core.annotation.Module
import org.koin.core.annotation.Singleton
/**
* Expected settings module to access key-value pairs across different platforms
*/
@Module
@Configuration
expect class SettingsModule {
@Singleton
fun provideSettings(): Settings
}
Actual:
package net.newpipe.app.di
import android.content.Context
import androidx.preference.PreferenceManager
import com.russhwolf.settings.Settings
import com.russhwolf.settings.SharedPreferencesSettings
import org.koin.core.annotation.Configuration
import org.koin.core.annotation.Module
import org.koin.core.annotation.Singleton
@Module
@Configuration
actual class SettingsModule(private val context: Context) {
@Singleton
actual fun provideSettings(): Settings = SharedPreferencesSettings(
PreferenceManager.getDefaultSharedPreferences(context)
)
}theimpulson
05/04/2026, 8:36 AMDmitry Stakhov
05/04/2026, 8:38 AMtheimpulson
05/04/2026, 8:40 AMDmitry Stakhov
05/04/2026, 9:10 AM@Singleton
fun provideSettings(context: Context): Settings = ...
When you build for Android the Koin plugin will bind your provideSettings function to your Moduletheimpulson
05/04/2026, 9:23 AMtheimpulson
05/04/2026, 9:24 AMDmitry Stakhov
05/04/2026, 9:24 AMDmitry Stakhov
05/04/2026, 9:25 AMtheimpulson
05/04/2026, 9:27 AMDmitry Stakhov
05/04/2026, 9:30 AM@Module
@ComponentScan("com.example")
class MyModule
All definitions from com.example will be included into this module. If you have two modules with this annotation and package name, then definitions will be included into both modules. But usually I wouldn't recommend doing this.theimpulson
05/04/2026, 9:32 AMDmitry Stakhov
05/04/2026, 9:34 AM