0Pricing
Kotlin Multiplatform Academy · Lesson

Declare a Shared Koin Module

Register your dependencies in commonMain.

Declare a Shared Koin Module is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. 🚀

Frequently asked questions

Is the “Declare a Shared Koin Module” lesson free?

Yes — the full text of “Declare a Shared Koin Module” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “Declare a Shared Koin Module”?

Register your dependencies in commonMain. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Declare a Shared Koin Module” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Declare a Shared Koin Module
  2. single vs factory Scopes
  3. Start Koin on Android & iOS
  4. Inject into ViewModels & Repos
← Back to Kotlin Multiplatform Academy