Skip to content

Koin 4.0 Release: Powered by Kotlin 2.0

Koin 4.0 Powered by Kotlin 2.0

 

Koin 4.0 is a major release, now based on Kotlin 2.0.20.

It brings significant improvements across Kotlin, Android, Compose, and Multiplatform APIs. This version also includes important deprecations and API clean-ups, all aimed at streamlining the framework and improving performance.

Here’s a detailed breakdown of what’s new and what you need to know:

Kotlin 2.0.20: A New Baseline

Ensure your project is using at least Kotlin 2.0.20. Older versions may lead to crashes due to changes in the Kotlin Multiplatform (KMP) API.

Core & Kotlin Multiplatform API Enhancements

Internal Optimizations:

  • Context Passing: More dynamic handling of injected parameters, improving the resolution order based on definitions, parameters, and scope.
  • Thread-Safe Collections: Improved internal collections for better stability in concurrent environments.
  • Kotlin Time API Use the Kotlin standard Time API instead of old internals, simplifying internal architecture.

 

Koin-Fu Project (Experimental)

The Koin-Fu Project is an experimental DSL project aimed at unifying the API and improving the user experience for better data handling and comprehension. The long-term goal is to support Koin-Fu through a Kotlin compiler plugin, moving away from the current reflection-based API. The project aims to refine the lambda and singleOf APIs and improve internal data for better configuration checks.

Android API Updates

ViewModel API: Now Multiplatform

The ViewModel API has been centralized in the koin-core-viewmodel package, making it fully multiplatform. Deprecated methods in the old ViewModel DSL are being phased out.

You can update your imports to org.koin.core.module.dsl.* to avoid warnings.

Screenshot 2024-10-15 at 10.41.12koinViewModel with a Compose Multiplatform app

AndroidX Startup: Optimized Loading

The new koin-androidx-startup package optimizes the startup process, reducing load times by up to 40%. The onKoinStartup delegate simplifies configuration in the Application’s initialization.

Activity & Fragment Scope Fixes

We've addressed scope propagation issues in Android Activity and Fragment lifecycle management.

Compose API Improvements

We've updated Koin’s Compose API for better Multiplatform support.

The koin-androidx-compose and koin-compose-viewmodel APIs now share a unified codebase, improving integration across platforms.

We've also added full lifecycle handling and stable WebAssembly (Wasm) integration.

Testing API Enhancements

Parameter Injection

We've added support for injected parameters in the Verify() API, making it easier to test dynamic behavior. We've also improved parameter injection to better handle missing or incorrect definitions.

Screenshot 2024-10-15 at 10.51.23

Missing Definition or Parameter Generation


We've enabled the Verify() API to automatically generate fixes for missing definitions, streamlining the testing process.

Screenshot 2024-10-15 at 10.53.03

Code suggestion to resolve missing definitions or parameter injection issues.

Ktor API Updates

We've updated Koin’s integration with Ktor 2.x, improving scope management and implementing UUID-based scope instance identification. We are also planning future integrations for Ktor 3. Watch this space 

Breaking Changes

Several deprecated APIs have been removed:

    • CheckModules: Replaced by the Verify() API.
    • ViewModel DSL: Now centralized in koin-core-viewmodel which is based on the new Multiplatform API.
    • Reflection-based APIs: The KoinReflect API and related annotations have been removed.
    • Android ViewModel API: Deprecated methods such as stateViewModel and sharedStateViewModel have been removed.
    • Compose API: Old methods like get, inject, and stateViewModel have been deprecated in favor of newer integrations.

Renamings:

We've renamed ApplicationAlreadyStartedException  to KoinApplicationAlreadyStartedException for improved clarity.

 

Documentation and Resources

We've moved package information to the Koin website, to reduce clutter in project README files.

Updated guides cover Compose integration, isolated contexts, and advanced use cases. You can find more detailed documentation on the updated Compose page