Kotlin development boost with the release of Koin 3.4 and Koin Annotations 1.2 cheat sheet (download at bottom of page)
You may know by now that the latest releases for Koin in H1 2023 - Koin 3.4 and Koin Annotations 1.2 are out! You can now download the cheat sheet below..... And, for those who missed it, here's the lowdown.
Koin 3.4 brings some cool updates, including catching up with Kotlin 1.8.10, upgrading Android dependencies, and adding support for Ktor 2.2.4. We've also updated the graph verification API Verify() to better detect cycles. Now, you don't need to declare primitives in your tests because they're already "whitelisted" types!
Speaking of testing, we've also got the
koin-android-test project that offers some great features for Android testing. With the new androidVerify() function, verifying Android-related modules is a breeze. Plus, it comes with a list of default Android types, including Context, Activity, Fragment, Application, SavedStateHandle, and WorkerParameters.
We've also introduced a new Kotlin Multiplatform API called KoinPlatform, making accessing all platforms for some main features easier. And for native targets, stay tuned - incoming versions of Kotlin may update targets or even deprecate/remove some old ones.
And finally, the Extension management system is here! It extends Koin's capacities, and our first extension includes a Coroutines engine, allowing you to run modules loading in Coroutines. With this experimental feature, you can load modules lazily and in the background, freeing up the current process. Some functions allow you to wait for completion with:
Extension Manager, Lazy Modules & Coroutines Engine
Let's optimize the startup process of Koin by implementing background modules loading through Coroutines. While this feature is still experimental and the API may change in future versions, it shows a lot of promise.
To achieve this objective, our first Koin Extension includes a Coroutines engine, which serves the following purposes:
- Defining lazy modules
- Background loading of lazy modules
- Allowing synchronous and asynchronous module loading
- Waiting and running code after loading completion
For example, let's consider the following two classes that need to be injected:
Let’s write lazy modules with it:
And finally, we can start the loading process with:
The process loads in the background, freeing up the current process. However, if you need to wait for completion, Koin offers a suspend function called
Koin.waitAllStartJobs() or the JVM blocking function
lazyModules() function from the Koin application DSL provides a new way to load modules, and it's up to you to choose between
lazyModules() in your application configuration.
Koin Annotations 1.2
As for Koin Annotations 1.2, it's getting stronger with the addition of top-level function annotations and the new
@KoinWorker annotation for declaring Worker components.
And now you've found the cheat sheet😎:
Ok, that's it for now. We have an announcement loading about Koin for Compose 1.0🎸. Watch. this. space!