Mindy is Minimum Dependency Injection library.
Feature:
- Resolve generics type parameter
- Resolve instance as singleton or else
- Create parameterized instance
build.gradle
allprojects {
repositories {
google()
jcenter()
maven{ url "https://dl.bintray.com/mobile-act/Mindy" } // need!
}
}
dependencies {
implementation 'mobile-act:mindy:VERSION' // adapt latest version
}
val mindy = Mindy()
// register type: String
mindy.register{ "Example" }
val value = mindy.resolve<String>()
interface IValue<T> {
val value: T
}
abstract class BaseValue<T>(override val value: T) : IValue<T>
class Value<T>(value: T) : BaseValue<T>(value)
class StringValue(value: String) : BaseValue<String>(value)
val mindy = Mindy()
// regster type: IValue<Int>
mindy.register<IValue<Int>>{ Value(10) }
// register type: IValue<String>
mindy.register<IValue<String>>{ StringValue("Example") }
// register type: IValue<IValue<String>>
// dependency resolve(): IValue<String>
mindy.register<IValue<IValue<String>>>{ Value(resolve()) }
val intValue = mindy.resolve<IValue<Int>>()
val stringValue = mindy.resolve<IValue<String>>()
val nestedStringValue = mindy.resolve<IValue<IValue<String>>>()
val mindy = Mindy()
mindy.register<IValue<String>> { StringValue("Example") }
val a = mindy.create<IValue<String>>()
val b = mindy.create<IValue<String>>()
// a and b is different instance
val mindy = Mindy()
mindy.register<IValue<IValue<String>>> { Value(resolve()) }
val a = mindy.create<IValue<IValue<String>>> {
register<IValue<String>> { StringValue("a") }
}
val b = mindy.create<IValue<IValue<String>>> {
register<IValue<String>> { StringValue("b") }
}
// a and b is different value
val mindy = Mindy()
mindy.register<IValue<String>>(name = "a") { StringValue("a") }
mindy.register<IValue<String>>(name = "b") { StringValue("b") }
val a = mindy.resolve<IValue<String>>(name = "a")
val b = mindy.resolve<IValue<String>>(name = "b")
// a and b is different instance/value
Now, Mindy is using @ExperimentalStdlibApi
by typeOf()
.
This library is under MIT License
- using Kotlin Standard Library, published by Apache License 2.0
- using JUnit5, published by Eclipse Public License 2.0
- using Kotlin Standard Library, published by Apache License 2.0
- using AndroidX, published by Apache License 2.0
- using ConstraintLayout, published by Apache License 2.0
- using AndroidX Test, published by Apache License 2.0
- using JUnit4, published by Eclipse Public License 1.0
ToDo: Write
Author: @MeilCli