Room Setup
Opened this issue · 1 comments
So, I was trying to setup Room in this project.
I created the @Entity
and @Dao
classes inside the speakers
module, as they should be used only inside that module.
Next, I created the AppDatabase
class in the app
module since it requires access to all Entity
and Dao
classes in all modules (for example @Database(entities = [SpeakerModel::class, SessionModel::class], version = 1)
)
The issue is, I couldn't figure out how to access AppDatabase
from different modules. Access to AppDatabase
is not really required, but if anyone can figure out a way to access instances of @Dao
in respective modules, that'll be of much help.
Here's what I've done so far: https://github.com/adnan-SM/droidconChennaiV2/tree/roomsetup
It's a tricky problem to solve and there are multiple ways to solve it:
- Each module has it's own
AppDatabase
-> it's database file
Pro: Super clean database layer
Con: Relationship between entities in different module is not possible - Create a
db-module
which has everything related to database and this module is implemented by all the features, this way they get access toAppDatabase
.