GithubHelp home page GithubHelp logo

hugolefrancois / koin-annotations Goto Github PK

View Code? Open in Web Editor NEW

This project forked from insertkoinio/koin-annotations

0.0 0.0 0.0 519 KB

Koin Kotlin Compilers

License: Apache License 2.0

Shell 0.15% Kotlin 99.85%

koin-annotations's Introduction

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:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.