https://github.com/memoizr/shank
Simple dependency injection framework
https://github.com/memoizr/shank
Last synced: 3 months ago
JSON representation
Simple dependency injection framework
- Host: GitHub
- URL: https://github.com/memoizr/shank
- Owner: memoizr
- License: apache-2.0
- Created: 2015-10-24T09:49:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-02-21T18:07:11.000Z (over 4 years ago)
- Last Synced: 2025-03-26T20:51:34.193Z (3 months ago)
- Language: Kotlin
- Size: 450 KB
- Stars: 55
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://travis-ci.org/memoizr/shank)
[](https://codecov.io/gh/memoizr/shank)
[](https://jitpack.io/#memoizr/shank)
[](http://www.apache.org/licenses/LICENSE-2.0.html)
# Shank### TLDR TUTORIAL:
### 1. Declare your modules by extending `ShankModule`, where you specify how the object should be created
```kotlin
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
```kotlin
registerModules(MyModule, SomeOtherModule, ...)
```### 3. Then you can inject your dependencies anywhere
```kotlin
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.