Group Group Group Group Group Group Group Group Group

MVVM on Android · Model Repository |


This is a companion discussion topic for the original entry at


In the CreaturemonApplication we have the following code:

    companion object {
        lateinit var database: CreatureDatabase

That means that the database dependency will be static available for the hole app. Once we have it on the Application class.

My question is: that is the best approach for sharing dependencies ?


Thanks for the question, Amadeu!

The best approach is probably to use dependency injection to give the repository access to the database and the DAOs. We’re going to take a look at dependency injection in a future course. Both with a framework like Dagger and also without, e.g. you can pass the database into the repository constructor as a property.

1 Like

In the the Creature class, I had to change val to var in order to run the app.

 error: Cannot find setter for field.
private final attributes = null;

Otherwise I got the above error.


@aaldous Thank you for sharing your solution - much appreciated! :]