koin v0.2.x Release Notes
-
🔀 Koin & Koin-Android project has meen merged
DSL
- Module/AndroidModule class must now give a
context()
function implementation, to return a Context object. ThedeclareContext
function unlock the Koin DSL to describe dependencies and injection:
class MykModule : Module() { override fun context() = declareContext { ... } }
- You can now bind additional types for provided definitions
Kotlin class MykModule : Module() { override fun context() = declareContext { provide { Processor() } bind { ProcessorInterface::class} } }
Scope
- 👀 You can declare/reuse paths in your modules, with
modulePath {}
operator. See paths section - 🚀 Release modulePath instances with
release()
on a KoinContext
class MainActivityModule : Module() { override fun context() = declareContext { // Scope MainActivity modulePath { MainActivity::class } // provided WeatherService provide { WeatherService(get()) } } }
Android
- 🚚
KoinAwareContext
interface used to setup Android application (KoinApplication & KoinMultidexApplication are removed)
class MainApplication : Application(), KoinContextAware { /** * Koin context */ lateinit var context: KoinContext /** * KoinContextAware - Retrieve Koin Context */ override fun getKoin(): KoinContext = context override fun onCreate() { super.onCreate() // insert Koin ! context = Koin().init(this).build(MyModule()) // ... } }
by inject<>()
function operator to inject any dependency in any Activity or Fragment
class MainActivity : AppCompatActivity() { // inject my WeatherService val weatherService by inject<WeatherService>() }
Koin
- 🏗 Koin builder takes module instances (instead of module classes):
// fill applicationContext for Koin context val ctx = Koin().init(applicationContext).build(Module1(),Module2()...)
Internal rework for simpler use with Scopes:
- 🏗
Koin().build()
return KoinContext - 🚚 factory, stack operators have been removed, for the modulePath fatures
- ✂ delete/remove replaced with
release()
Scope operation - import is replaced with module instances load
- 🚚 All reflection & kotlin-reflect code have been removed
- Module/AndroidModule class must now give a