Opening the Koin 1.0.0 — Beta version
Hi Koin users! This is it … we are releasing the first public beta version of Koin 1.0.0. Lots of work have been done since our last blog post. The website has been greatly reviewed to give you the most helpful about that. Let’s get into the details to see the new cool things 🙂
Your new bookmark 👉beta.insert-koin.io
1.0.0-beta-3 version of Koin has been published and is ready for you. As usual, upgrade your Gradle script with the new version number:
// Koin for Kotlin
// Koin for Unit tests
// Koin for Android
Check the setup page for the entire list of available Koin modules.
The first thing to show you is our simplification of the Koin DSL, by renaming:
Our target is to make the DSL simple to read and write (and without any conflict with technical terms). We make Koin “modules” and we use some “single” instance definitions, that’s it 👍! Below a quick example of Koin module with Koin 1.0:
Core features: better & stronger
Visibility API was not very usable. You can now retrieve a component with its module path: specify the
module parameter when using get/inject function (no need of giving a special name):
For definitions and modules, we have now 2 flags to specify additional behavior:
createdAtStart: create instance of module/definition with startKoin() function
override: definition and module override must be explicit. You have to specify
override=trueon definition or module that need overriding existing content.
The definition flags documentation chapter gives more details about it.
One last thing to note, is the renaming of the
releaseContext() function to
release(). This last take a module path to release.
Smarter Injection Parameters
The dependency injection API has been reviewed to allow you to use destructured declaration directly, without forcing you to use a Map of values:
When requesting an instance, just use the
parametersOf() function to specify which params to provide. You will find Further reading in injection parameters chapter.
Koin for Java developers
One big news is the coming of the
koin-java project. The big idea is to bring easy start & injection to Java with static helpers:
You have to describe Koin module in Kotlin, but all your classes can be in Java! KoinComponent static helper is brought by
KoinJavaComponent class and startKoin is ported by
KoinJavaStarter. Check out the koin-java Quick Reference page for more info.
Advanced core features
Tired of writing several
get() to your constructor? If you are not afraid of using a bit of reflection, the
koin-reflect project complete the
koin-core project with the
build() function to help you build your definition from its primary constructor:
Koin core is purely written without any reflection API. Here is a dedicated side feature, to offer a smarter way of writing definitions at a very small cost: the time to take your constructor and find each parameter of it. If you are not constrained with performances, up to you to test it else keep writing your definition directly with
Breaking news for Android
Lots of work on the Android side! Projects have been renamed thanks to their feature inside. We have now the following Android projects:
// Koin for Android
// Koin Android Scope feature
// Koin Android ViewModel feature
koin-androidx has been dropped and won’t be updated anymore.
The newcomer is the scoping feature ported by
koin-android-scope which help you bind an Android component’s lifecycle to a module. On the lifecycle’s end, we drop instances from the target module. For this, use the
scopedWith() function like below:
The ViewModel Koin feature is done by
koin-android-viewmodel project and has the same target as the old
koin-android-architecture: bring easy to use out of the box dependency injection for Android Architecture ViewModel components.
One last big thing:
starKoin() doesn’t need you to run from
Application class anymore. The function needs only a
Context instance to run and be started from any Android class if needed:
Another thing to note also, is the change of the DSL function
androidContext() to suit to the new changes
Go get the Android documentation chapter to read all about it!
Unlocking AndroidX version
For those who wants to test the new Android packaging system, we have prepared the AndroidX version of projects that are impacted:
// Koin AndroidX Scope feature
// Koin AndroidX ViewModel feature
Features are the same than the standard package, but with new AndroidX packages.
koin-spark, we can now use the
koin-logger-slf4j logger to help you log with the desired logging implementation (logback, log4j …).
Ktor extensions have been completed with
SparkJava needs you to extends
SparkController interface if you want to declare a controller.
Getting Started Projects on Github
All the getting started projects are available on Github or are directly downloadable with a zip file. Go check this 🚀
Rendez-vous @ beta.insert-koin.io
The beta version of the website is available at beta.insert-koin.io. The following points have been greatly improved:
- project documentation
- quick references
- getting started sections
How can you help us?
This public beta allows us to give you the last version of Koin and you to give us your feedback about all those changes. Don’t hesitate to come to contribute!