Question I have created a multi module kmp app D...
# multiplatform
d
Question I have created a multi module kmp app Data Domain Di Design system Compose app My question is for Data module where I want to implement Room Db, the problem is it requires context and passing context in Data layer seems anti pattern. I have tried actual/expect mechanism but still its not working. Any suggestions are valuable.
s
Are you using Room 2.7.0 or newer, which supports KMP? And have you read through the Room KMP guide here? https://developer.android.com/kotlin/multiplatform/room
Can you share how you tried to use actual/expect and how it was failing?
d
Is it safe to add android context lib in the Data module?
s
In your android implementation of the expect/actual
RoomDatabase.Builder<AppDatabase>
, sure. If you want to avoid that, you'll need to create your
RoomDatabase.Builder<AppDatabase>
with a
Context
closer to your application layer and then use dependency injection to bring it into the :data module
d
Yes, I am able to resolve this with koin androidContext(). I've injected the context from my composeApp and used in Di module.