Skip to content

hugolefrancois/koin-annotations

 
 

Repository files navigation

Koin Annotations

The goal of Koin Annotations project is to help declare Koin definition in a very fast and intuitive way, and generate all underlying Koin DSL for you. The goal is to help developer experience to scale and go fast 🚀, thanks to Kotlin Compilers.

Current Version

Here below is the current version:

Warning: while this is still in beta. There can be some breaking changes coming in next releases 🙏

koinAnnotations = "1.0.0-beta-2"

Koin 3.2+ is required

Setup

First, setup KSP plugin like this, in your root build.gradle:

plugins {
    id "com.google.devtools.ksp" version "1.6.10-1.0.2"
}

Use the following dependencies in your Gradle dependencies section:

// Koin Annotations
implementation "io.insert-koin:koin-annotations:$koinAnnotations"
// Koin Annotations - Ksp Compiler
ksp "io.insert-koin:koin-ksp-compiler:$koinAnnotations"

On your app add the following to generated source code:

  • On Kotlin project:
sourceSets.main {
    java.srcDirs("build/generated/ksp/main/kotlin")
}
  • on Android project:
android {
  applicationVariants.all { variant ->
          variant.sourceSets.java.each {
              it.srcDirs += "build/generated/ksp/${variant.name}/kotlin"
          }
      }
}

Getting Started

Not familiar with Koin? First take a look at Koin Getting Started

Tag your components with definition & module annotations, and use the regular Koin API.

// Tag your component to declare a definition
@Single
class MyComponent
// Declare a module and scan for annotations
@Module
@ComponentScan
class MyModule

Use the org.koin.ksp.generated.* import as follow to be able to use generated code:

// Use Koin Generation
import org.koin.ksp.generated.*

fun main() {
    val koin = startKoin {
        printLogger()
        modules(
          // use your modules here, with generated ".module" extension on Module classes
          MyModule().module
        )
    }

    // Just use your Koin API as regular
    koin.get<MyComponent>()
}

That's it, you can use your new definitions in Koin with the regular Koin API

QuickStart

Below some quickstart apps:

About

Koin Kotlin Compilers

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 99.9%
  • Shell 0.1%