0Pricing
Kotlin Multiplatform Academy · Lektion

Ein gemeinsames Koin-Modul deklarieren

Ihre Abhängigkeiten in commonMain registrieren

Ein gemeinsames Koin-Modul deklarieren ist eine kostenlose Kotlin Multiplatform Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Kotlin Multiplatform Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Kotlin Multiplatform Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Why Wire Things Together

Your app is full of objects that need each other: a repository needs a client, a use case needs the repository. Dependency injection hands those pieces over for you.

Meet Koin

Koin is a lightweight DI library written in pure Kotlin, so it runs happily in commonMain and works on both Android and iOS. 🎉

Add the Dependency

You pull Koin into your shared module the same way you add any other library, listing the core artifact in your version catalog or build file.

implementation("io.insert-koin:koin-core:3.5.0")

A Module Is a Recipe Book

A Koin module is just a list of recipes telling Koin how to build each dependency. You declare it once and reuse it everywhere.

Write Your First Module

The module { } builder collects your definitions. An empty one is valid; you fill it with recipes next.

val appModule = module {
}

Register with single

Inside the module, single { } registers one shared instance Koin reuses for the whole app, perfect for a repository.

val appModule = module {
    single { UserRepository() }
}

Wire Dependencies with get

When one object needs another, call get() inside the recipe. Koin looks up the matching definition and passes it in automatically.

single { UserRepository(api = get()) }

Order Does Not Matter

You can declare definitions in any order. Koin resolves the graph lazily, so a recipe can safely get() something defined further down.

Keep It in commonMain

Because Koin is multiplatform, place appModule in commonMain. Both your Android and iOS apps then share the exact same wiring.

Group Related Modules

Large apps split definitions into several modules, like a data module and a domain module, then combine them later when starting Koin.

val dataModule = module { single { ApiClient() } }

A Function That Returns It

A common pattern exposes your module from a function, making it easy for each platform to grab the shared definition.

fun appModule() = module {
    single { UserRepository(get()) }
}

Quick Check

Let's lock in what a Koin module does.

Recap

You met Koin, added it to your shared module, and wrote a module that registers dependencies with single and links them using get. One recipe book, both platforms. 🚀

Häufig gestellte Fragen

Ist die Lektion „Ein gemeinsames Koin-Modul deklarieren“ kostenlos?

Ja — der vollständige Text von „Ein gemeinsames Koin-Modul deklarieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Kotlin Multiplatform Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Kotlin Multiplatform Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Ein gemeinsames Koin-Modul deklarieren“?

Ihre Abhängigkeiten in commonMain registrieren Du übst Kotlin Multiplatform Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Kotlin Multiplatform Academy zu starten?

Keine Vorkenntnisse erforderlich. Kotlin Multiplatform Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Ein gemeinsames Koin-Modul deklarieren“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Kotlin Multiplatform Academy-Lektion Code schreiben und ausführen?

Ja. Jede Kotlin Multiplatform Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Ein gemeinsames Koin-Modul deklarieren
  2. single- vs. factory-Scopes
  3. Koin auf Android und iOS starten
  4. In ViewModels und Repos injizieren
← Zurück zu Kotlin Multiplatform Academy