Dependency Injection: the pattern without the fram...
# feed
m
Dependency Injection: the pattern without the framework by @jmfayard https://blog.kotlin-academy.com/dependency-injection-the-pattern-without-the-framework-33cfa9d5f312
👌 2
r
IDK much about the Android specifics, but it’s always nice to see the articles on framework-less DI.
c
If only to realize that framework-full DI is pretty darn useful 🙂
r
Meh, I only seem to use DI frameworks when forced to 😛
c
I have yet to see a convincing DI native approach that offers something even remotely similar to modules (which are a very important part of an effective DI solution).
d
after using gorgeous spring di i can't look on other "lightweight" di frameworks without tears (hello dagger2)
t
This is my kotlin dependency injection framework:
Copy code
abstract class InjectionModule {
    fun <T : Any> singleton(provider: () -> T) = lazy(provider)
    
    fun <T : Any> provide(provider: () -> T) = TransientProviderProperty(provider)
}

class TransientProviderProperty<out T : Any>(private val _provider: () -> T) {
    operator fun getValue(thisRef: Any?, property: KProperty<*>) = _provider()
}
c
@deviant Interesting, to me it’s Spring DI that looks bloated and inconvenient, while Dagger 2 is lean and more statically typed too