3 min read

Koin 3.2.2 - Fresh updates before the next milestones!

Koin 3.2.2 has been released. It's time to talk about the new fresh updates (especially for Jetpack Compose & Android Scope) and what's coming in Koin 3.3.
Koin 3.2.2 - Fresh updates before the next milestones!
Picture based on photo from Dan Cristian Pădureț

Hello Koin users 👋

It has been a while since my last Koin release post. This summer, we were around at conferences meeting developers that are using Koin. It's always a great time to meet you all and talk about your experience.

If you didn't see the last conference about Koin, check  "Diving into Koin 3.2 & Koin Annotations 1.0". Now, let's talk about some fresh updates 👇

Opening Version Tracks

Since the beginning of the year, we are communicating about our roadmap and version structure. For us, it's important to clarify what kind of delivery you will have for each kind of version (patch, minor, major).

With the release of 3.2 version tracks this summer, we are opening version tracks between projects: Koin projects are becoming more independent in terms of delivery. We can deliver patches for different projects, without delivering them all together. Also, this allows the introduction of new independent rhythms of delivery. Only major versions will impose projects to be based on the same major version.

Below, you can find the changelogs per track:

  • Core & Test - 3.2.2 (link)
  • Android - 3.2.2 (link)
  • Jetpack Compose - 3.2.1 (link & link)
  • Ktor - 3.2.2 (link)
  • Annotations - 1.0.3 (link)

ViewModel API Fixes for Compose

In the Koin community, we have a lot of questions regarding Jetpack Compose usage. Interestingly, we are unlocking new ways to use Dependency Injection in Compose applications.

While waiting for new features to come (Koin 3.3), for now we are fixing important topics for Compose:

  • Navigation arguments are passed with SavedStateHandle
  • Qualifier resolution is fixed

We need to deprecate ViewModel Lazy API. With the last realignment with Android ViewModel API 2.4.0, Jetpack Compose 1.1 breaks while trying to use Lazy API. The other thing is, you don't need Lazy API in Compose (don't use the by delegate style). Just use getViewModel ( alias koinViewModel )  function to resolve your ViewModel instances.

Thanks John for your super fast tweet 😁

Android Scope - Delegate API Deprecations

Lastly introduced in Koin 3.1.x branch (see "Understanding Android Scopes with Koin" article), the Scope delegate API allowed you to help declare a Koin scope and bind it to the lifecycle of your Activity or Fragment.

The API was consisting in: activityScope() , activityRetainedScope() and fragmentScope() as lazy delegate functions. Those APIs are deprecated to propose eager functions, that need to be used in the right place of your lifecycle (onCreate functions usually).  Having a more explicit API allows you to setup your scopes in the right place and avoid fewer side lazy effects.

The new functions are :

  • createActivityScope() , createActivityRetainedScope()  - create and bind scope to the current Activity's lifecycle
  • createFragmentScope()  - create and bind scope to the current Fragment's lifecycle (and parent's lifecycle)
class MyActivity() : AppCompatActivity(contentLayoutId), AndroidScopeComponent {

    override var scope: Scope? = null
    val presenter : MyPresenter by inject()

    override fun onCreate(savedInstanceState: Bundle?) {
        // create Koin scope

The underlying Android resolution API is now safer in terms of Scope resolution. The ScopeActivity and ScopeFragment classes are kept unchanged but use the new Scope API functions.

We assume here a small breaking on the AndroidScopeComponent interface:

interface AndroidScopeComponent {
    var scope: Scope?
    fun requireScope() : Scope

As you may see, the scope property is now a variable with Scope? type. We prefer to let you fix this part and have a safer use of scopes, rather than keep this API for too long. The community was really demanding on this topic.

The documentation is there if you need more details: https://insert-koin.io/docs/reference/koin-android/scope#scope-for-android-components-321-update

New Starter Projects

The Koin starter projects let you have a minimal starting project with the many kinds of Koin applications (Kotlin, Android, Ktor, Annotations ...).

We are reworking them to add a KMM and a Jetpack Compose starter projects to the list. Stay in touch 👍

What's Next? Koin 3.3

It's now time to talk about the big things coming around:

  • Update to the latest frameworks & libraries versions (Kotlin 1.7.x, Compose 1.2, Ktor 2.1.x ...)
  • Improvement for Constructor DSL
  • New ViewModel API to simplify the developer experience and align on the latest 2.5.x API
  • New Android Jetpack Compose DI features

We are also planning to cover Jetbrains Compose with Koin, and then expand dependency injection features to different kinds of Compose projects.

Well, that's many good topics to come :) Hope you'll enjoy all of them.

Do not forget to subscribe to our blog to be sure to see all our fresh news! Feel free to give your feedback on Twitter:  @insertkoin_io