Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.43 KB

README.md

File metadata and controls

42 lines (31 loc) · 1.43 KB

Inversion of Control for Kotlin with DSL

IoC implementation for Kotlin/Multiplatform with multithreading.

CircleCI Codacy Badge

import org.angelos.ioc.Config
import org.angelos.ioc.Container
import org.angelos.ioc.Module

// Implementing a custom module type for the container, 
// which represents an item.
open class ExampleModule : Module

// Creating modules that can be dispatched as services.
class Module1 : ExampleModule()

class Module2 : ExampleModule()

class Module3(val one: Module1, val two: Module2) : ExampleModule()


// The IoC implementation.
class ExampleContainer : Container<String, ExampleModule>() {
    operator fun invoke(block: ExampleContainer.() -> Config<String, ExampleModule>) = config { block() }
}


fun main() {
    val ioc = ExampleContainer()
    ioc {
        mapOf(
            "one" to { Module1() },
            "two" to { Module2() },
            "three" to { Module3(get("one"), get("two")) }
        )
    }

    val three: Module3 = ioc["three"]
}