Giter Club home page Giter Club logo

koin-module-processor's Introduction

koin-module-processor

Annotation Processor to generate a list of Koin Modules.

Usage

Setup

In your module buildscript, add the KSP plugin:

plugins {
    id("com.google.devtools.ksp") version "1.6.0-1.0.1"
}

Then add the following dependencies:

val kmpLatestVersion = "2.0.0"
implementation("com.rocca23:koin-module-processor:$kmpLatestVersion")
ksp("com.rocca23:koin-module-processor:$kmpLatestVersion")

Declaring Koin modules

Declare your Modules as top-level properties, annotated with @KoinModule:

// MyModule.kt

@KoinModule
val myModule = module {
    single {
        // ...
    }
    factory {
        // ...
    }
}

Installing the modules

After building the project, a top-level property named org.koin.generated.koinModules is created. This is a list of all the annotated modules discovered by the annotation processor. You can finally add the generated list to your Koin initialization:

startKoin {
    androidContext(context)
    modules(koinModules)
}

Whenever you add a new Koin Module, it will be automatically added to the same list.

Avoid conflicts in multi-module projects

To avoid ambiguity and class-loading conflicts in case you want to use KMP in multiple project modules, you can specify a prefix to be used in the generated names by passing an argument named "kmp.prefix" to the annotation processor in your build.gradle.kts:

kapt {
    arguments {
        arg("kmp.prefix", "library")
    }
}

This way, the generated module list will be named (as per the above example) libraryKoinModules.

koin-module-processor's People

Contributors

rocca23 avatar

Watchers

James Cloos avatar  avatar

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.