Skip to content

memoizr/shank

Repository files navigation

Build Status codecov GitHub license

Shank

TLDR TUTORIAL:

1. Declare your modules by extending ShankModule, where you specify how the object should be created

object MyModule: ShankModule() {
    val alwaysNew = new { -> Random() }
    val myClassDependency = singleton { -> MyClass() }
    val dependencyWithParam = singleton { p: String -> OtherClass(p) }
}

2. Then you register them at your earliest convenience

registerModules(MyModule, SomeOtherModule, ...)

3. Then you can inject your dependencies anywhere

fun myCode() {
    ...
    blah.foo()
    ...

    myClassDependency().callSomeMethodOfMyClass()

    dependencyWithParam("foooo").callSomeMethodOfOtherClass()

    alwaysNew().nextInt()

    ...
    blah.blah()
    ...
}

That's the end of the tutorial, you know how this library works. Now you can go have some actual coffee.