I need to initiate Room in its repository. But to do that I need context. If I pass context through the viewmodel i got this message This field leaks a context object
.
I have checked this answer but they init the repository object in the view layer but according to the clean architecture view layer shouldnt know anything about data layer right? So how to organize the delivery of the context
to the data layer without DI?
class MainViewModel(private val context: Context) : ViewModel() {
private val roomManager : RoomManager = RoomManagerImpl(context)
private fun addItem(){
roomManager.addItem()
}
}
Here is repository code
class RoomManagerImpl(private val context: Context) : RoomManager {
private val db = Room.databaseBuilder(
context,
AppDatabase::class.java, "database-name"
)