Koin 0.8.0 released — welcome to koin-spark & koin-android-architecture

Arnaud Giuliani
Jan 4, 2018 · 3 min read

Happy new year! Here is our first release of 2018.


Previous release of Koin (0.7.1) was focused on simplification: Koin DSL is now simpler and doesn’t require to put it in a class anymore. API has been fixed and simplified to help you write your DI in the most simple way possible. We always keep in mind: being simply pragmatic.

With release 0.8.0, Koin now has some new modules: koin-spark and koin-android-architecture. Let’s see quickly what they bring.

Koin with Android Architecture

Image for post
Image for post

A new module has been created to bring Koin support to Android Architecture Components. Before just add the needed gradle dependency:

compile "org.koin:koin-android-architecture:0.8.0"
  • viewModel is a DSL keyword (specialized `provide` alias for ViewModel), to declare an Architecture Components ViewModel
  • getViewModel() is a function in Activities and Fragments, to get and bind ViewModel components

Koin provides a factory to Android Architecture API, to bind needed instance from Koin. Just declare a ViewModel class in your module, with viewModel keyword:

Image for post
Image for post

Use constructor injection into your ViewModel class (here we inject MyRepository component):

Image for post
Image for post

Get it from your Activity or Fragment, with getViewModel():

Image for post
Image for post

Voila ! :) You can alsotest your ViewModel classes, and inject it into test classes, with koin-test module.

A sample project has been written to illustrate those features: Android Weather MVVM

Koin for SparkJava (Kotlin)

Image for post
Image for post

koin-spark brings some features to help you structure your code with sparkJava. Just add the needed gradle dependency:

compile "org.koin:koin-spark:0.8.0"
  • controller is a DSL keyword (specialized `provide` alias), to declare Spark controllers classes
  • start() is a function to start Spark server (optional port number) — lambda expression to allow the start of Koin and any controller instantiation
  • runControllers() is a function to instantiate all spark controllers, declared with controller keyword DSL

Write a Spark controller (use constructor injection):

Image for post
Image for post

Declare it in your module with controller keyword:

Image for post
Image for post

Just run it:

Image for post
Image for post

Your spark controller classes can be injected in KoinTest classes, with koin-test. A SLF4J logger has been added, to be compatible with Spark logging system.

Check the sample project has been written to illustrate those features: SparkJava Hello WebApp

Sample projects externalized to koin-samples

Sample projects have been moved out to a separated github repository (koin-samples repository) to allow users to just checkout samples and not the whole Koin projects with its complex build system.


Hope those new modules will help you in your Kotlin development. Cheers 👍

Don’t miss our new website. Rendez-vous at insert-koin.io

Image for post
Image for post

Koin developers

Latest news about Koin

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store