Mobile Development 10 min read

How Koin Annotations 2.2 Makes Migrating from Dagger/Hilt to Koin Seamless

Koin Annotations 2.2 introduces JSR‑330 compatibility, predefined scope archetypes, smart module configuration, and built‑in performance monitoring, enabling Android and Kotlin Multiplatform projects to migrate from Dagger or Hilt to Koin safely, progressively, and with minimal code changes.

AndroidPub
AndroidPub
AndroidPub
How Koin Annotations 2.2 Makes Migrating from Dagger/Hilt to Koin Seamless

Koin Annotations 2.2 is now officially released, focusing on migration convenience, interoperability, and development safety, allowing projects moving from Dagger or Hilt to Koin to enjoy a smoother transition while keeping the framework simple and letting developers concentrate on application logic rather than tool configuration.

Version Overview

The core features of Koin Annotations 2.2 include:

JSR‑330 Compatibility : full support for @Inject, @Singleton, @Named and other Jakarta annotations, aligning with the standards used by Dagger and Hilt.

Scope Archetypes : predefined Android and multiplatform scopes such as @ActivityScope and @ViewModelScope.

Smart Configuration : use @KoinApplication and @Configuration for automatic module discovery and configuration management.

Built‑in Performance Tracing : the @Monitor annotation integrates performance monitoring directly into the dependency graph.

JSR‑330 Compatibility — Standardized Dependency Injection for Kotlin

Koin Annotations 2.2 adds support for the JSR‑330 (Jakarta / Javax Inject) annotation specification, enabling seamless switching between Koin and other DI frameworks like Dagger and Hilt. Developers can now declare dependencies with standard annotations such as @Inject, @Singleton, @Named, and @Qualifier without altering existing code structures.

@Singleton
@Named("primary")
class PrimaryDatabase @Inject constructor(
    @Named("cache") private val cache: Cache
) : Database

Koin also supports custom qualifiers:

@Qualifier
@Retention(RUNTIME)
annotation class Dispatcher(val type: NiaDispatchers)

enum class NiaDispatchers { Default, IO }

class TimeZoneBroadcastMonitor @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher,
    private val context: Application) : TimeZoneMonitor

Reduce Migration Risk

In large codebases, switching DI frameworks can be risky. Koin Annotations 2.2 provides features that help developers gradually and safely migrate :

Coexistence Mechanism : can run alongside Dagger, Hilt, etc.

Progressive Migration : supports module‑by‑module migration without a full rewrite.

Compile‑time Validation : KOIN_CONFIG_CHECK validates configuration at compile time with clear error messages.

Readable Generated Code : auto‑generated Koin DSL is easy to debug and trace.

Scope Archetypes — Built‑in Lifecycle Management

Following the introduction of Scope Archetypes DSL in Koin 4.1, Koin Annotations 2.2 expands it with predefined scope annotations for common Android and multiplatform scenarios:

Android Platform

@ActivityScope

– binds to the Activity lifecycle. @ActivityRetainedScope – retains state across configuration changes. @FragmentScope – binds to the Fragment lifecycle.

Kotlin Multiplatform

@ViewModelScope

– compatible with Android ViewModel and Compose Multiplatform.

@ViewModelScope
class ViewModelScopedRepository(val api: ApiService)

@ActivityScope
class ActivityService(val global: GlobalService)

@FragmentScope
class FragmentService(val global: GlobalService, val activity: ActivityService)

Constructor‑injected ViewModel example:

@ViewModelScope
class MyScopedVM(val api: ApiService)

@KoinViewModel
class MainActivityViewModel(val myScopedVM: MyScopedVM, val userDataRepository: UserDataRepository) : ViewModel()
Example project (Hilt → Koin): https://github.com/kotzilla-io/nowinandroid_koin_annotations

Smart Configuration — Flexible Module Management

In large projects, modular configuration is key. Koin Annotations 2.2 introduces two important annotations: @Configuration – marks modules that can be scanned. @KoinApplication – automatically scans and aggregates these configurations to generate the startup entry point.

@Module
@Configuration
class DatabaseModule {
    @Singleton
    fun database() = PostgreSQLDatabase()
}

@KoinApplication
object ProductionApp {
    fun main() { ProductionApp.startKoin() }
}

Named configurations allow loading different modules per environment:

@Module
@Configuration("prod")
class ProdDatabaseModule {
    @Singleton
    fun database() = PostgreSQLDatabase()
}

@Module
@Configuration("dev")
class DevDatabaseModule {
    @Single
    fun database() = InMemoryDatabase()
}

@KoinApplication(configurations = ["prod", "dev"]) object ProductionApp

When placed on an Application class, @KoinApplication generates a startKoin() function that ties the correct modules together:

@KoinApplication
class NiaApplication : Application() {
    override fun onCreate() {
        startKoin {
            androidContext(this@NiaApplication)
        }
    }
}

Built‑in Performance Monitoring — Using @Monitor for Observability

Koin Annotations 2.2 adds observability at the DI layer. By annotating a class with @Monitor, Koin automatically generates a performance‑monitoring proxy that tracks execution time, call chains, and exceptions.

@Monitor
@Single
class UserService private val repository: UserRepository)

Method call tracing

Execution time statistics

Error and exception monitoring

Seamless integration with the Kotzilla platform for real‑time performance dashboards

Enable monitoring by adding the kotzilla-core dependency.

Production Ready, for Scalable Applications

Koin Annotations 2.2 is built on KSP and fully supports Kotlin Multiplatform, making it suitable for everything from lightweight apps to enterprise‑grade architectures.

implementation("io.insert-koin:koin-annotations:2.2.0")
ksp("io.insert-koin:koin-ksp-compiler:2.2.0")

Acknowledgements

We thank the community for its continuous feedback and contributions. Koin’s growth relies on open‑source collaboration, and we look forward to seeing more great projects built with Koin Annotations 2.2 .

Related Links 🔗

Koin Annotations official documentation – https://insert-koin.io/docs/reference/koin-annotations/start

Now in Android – Koin Annotations example – https://github.com/kotzilla-io/nowinandroid_koin_annotations

Koin JSR‑330 module – https://mvnrepository.com/artifact/io.insert-koin/koin-jsr330

Kotzilla platform (Koin performance monitoring & APM) – https://kotzilla.io/

MigrationAndroidPerformance MonitoringKotlindependency-injectionKoinJSR-330
AndroidPub
Written by

AndroidPub

Senior Android Developer & Interviewer, regularly sharing original tech articles, learning resources, and practical interview guides. Welcome to follow and contribute!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.