Starting Room components with Koin

Let’s start with a simple app that need to store weather data. For this, we use the following Room entity:

To use our WeatherEntity data, let’s define a Room DAO and a Room Database:

Check that your are using one the following Koin Android project:

implementation "org.koin:koin-android:$koin_version"

implementation "org.koin:koin-android-architecture:$koin_version"

Let’s assemble all things with a Koin module and declare our DAO & Database instances.

✅ The module consists in “bean” expression (singleton declaration) for each Room part. We reuse the WeatherDatabase instance to declare our WeatherDAO instance:

✅ Our app is now ready to inject our WeatherDAO in any class constructor👍

We can make a repository class and inject it by constructor: