I have many different feature modules and for each of them I've created a domain and data module. Here's my structure.
feature-a
- feature_a_domain
- feature_a_data
- feature_a_ui
feature-b
- feature_b_domain
- feature_b_data
- feature_b_ui
Each feature is a folder containing these three projects. Domain is pure kotlin, data depends on domain, and UI depends on domain interfaces while my app module injects data.
In some cases, feature_b might want to access data from the domain of feature_a. For example, I might do this in the feature_b_ui gradle:
implementation project ("feature_a:feature_a_domain")
I have got this building and launching. My main problem now has to do with dynamically loading the data modules I need with Koin for a particular feature.
If feature needs to dynamically load a data module, I have to reference the data module in the activity. This means that my feature_a_ui project needs to reference the data project as a dependency as so.
implementation project(':feature_a:feature_a_data')
I can then do this and bootstrap my dependencies for the dynamic feature.
class FeatureAActivity: AppCompatActivity() {
val model: FeatureAViewModel by viewModel()
private val loadFeatures by lazy { loadKoinModules(listOf(featureAModule, featureBDataModule)) }
private fun injectFeatures() = loadFeatures
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_feature_a)
loadKoinModules(listOf(featureAModule, featureBDataModule))
}
override fun onDestroy() {
super.onDestroy()
unloadKoinModules(listOf(featureAModule, featureBDataModule))
}
}
I'm not OK with this because I don't want my feature activity to know where it's data is coming from. I feel like I need some other module that's like an injector which binds all of this together but I can't do that in the app project because these feature modules and their data modules are dynamically loaded and delivered to the app.
Does anyone recommend a way that I can move this module loading outside of my feature activities ? This code seems against clean architecture.
Thank you :)