Koin X KMP Cheat Sheet
Koin X KMP Cheat Sheet
Koin X KMP Cheat Sheet
Cheat Sheet
And implement your module, following your
Koin Dependency Injection in platform-specific needs:
Koin is the Kotlin Multiplatform (KMP)
integration framework. Shared Code JVM
You can write code once and deploy it on Koin is a pure Kotlin framework. It interacts
multiple platforms, with KMP as the main naturally with your Kotlin shared code project the
cross-platform technology, and Koin as the same way as your JVM or Android project.
Dependency Injection framework.
Define Koin modules for the needed classes to
inject into your application.
Koin offers a fully Kotlin-centric approach,
leveraging the language's features and syntax
We recommend utilizing constructor injection
to provide a simpler and more intuitive DI whenever possible.
experience. Alternatively, the KoinComponent interface can
assist in dependency injection through properties. iOS
Multiplatform Application Setup
Phyllis
Take a look at the Kotlin KMPSchwaiger
getting started guide to
help start your new Kotlin Multiplatform application
Koin Annotations & KMP Implementing Native Dependency Starting Common & Native Modules
To integrate Koin Annotations into your KMP project,
Modules After defining your common Koin modules and
begin by following the KSP guide from Google. implementing the necessary native modules,
It’s also possible to define a Koin module, for a
initiate dependency initialization by invoking
specific platform. Use the actual Kotlin keyword
your native module from the shared code:
After integrating the Google KSP plugin, add the to define it:
koin-annotations & koin--ksp-compiler
dependencies to your KMP setup. Detailed steps can
be found in this tutorial.
insert-koin.io
Kotlin Multiplatform (KMP)
Cheat Sheet
Injecting Dependency - Wrapper Strategy To achieve this in iOS, simply implement the code below:
Injecting with ViewModels and KMM- KMP Settings library is shown below:
ViewModel
You can declare a ViewModel, usage across Android
and iOS with KMM-ViewModel.
Injecting Dependency - Koin Component
Strategy For this, incorporate the KMMViewModel() class for
your ViewModel:
An alternative method involves using the
KoinComponent interface to inject properties into a
class that will be manually instantiated:
To call the Kotlin function from iOS, ensure that you use
Then, declare it in your Android module and use it in the
the appropriate native object parameter:
“classical” way, with by viewModel :