I'm setting up an Android project, where I've separated the code into different modules to have a bit of a cleaner structure. The modules are presentation, domain, data, di and app. I am including a diagram of the dependencies between them.
When I write a new screen using Compose in the presentation layer, I am including a preview. Of course, these screens need a viewmodel, and since Compose previews do not start the application, Koin is not running to inject this. Thus, the preview fails to inflate.
Koin provides a solution for this, allowing you to run it in the preview with whatever modules you want, so you can include a fake/dummy one if you want to. It looks something like this:
@Preview
@Composable
fun ConnectAccountScreenPreview() {
KoinApplicationPreview(application = { modules(onboardingModule) }) {
ConnectAccountScreen(onNavigateBack = {}, onNavigateToNext = {})
}
}
The issue I have with this is that I cannot create a fully fake module in the presentation layer, because it can't see the data layer, so the implementation of the repositories and the datasources are not available.
I could of course create a fake module in the DI layer, or use the real one, but the presentation layer has no visibility of the DI layer, and I cannot reference it, because it would create a circular dependency.
What is the cleanest way to solve this? Does my modularization setup just suck? Should I get rid of the previews? Can I include a fake module or a dependency that I'm not thinking of? If you need any further code to assist, just let me know. Thanks!
