I have a multimodule application with analytics feature. Since i want to use not only firebase analytics, i need to split the module into api and implementation. Also i will disable some analytics providers by BuildConfig setup. My project dependencies will look something like this:
app
...
feature:analytics-api
feature:analytics-firebase
feature:analytics-mock
How to get target implementation in application class?
interface ApplicationAnalytics {
....
fun setUserIdentifier(context: Context, clientId: String)
fun setUserProperty(context: Context, bundle: Bundle)
fun pushEvent(context: Context, event: Event)
}
My impl class:
class FirebaseAnalyticsImpl : ApplicationAnalytics {
....
override fun pushEvent(context: Context, event: Event) {
pushFirebaseEvent(context, event)
}
Module designation and potential problem area:
private val analyticsModule = module {
/*if(BuildConfig.WITH_ANALYTICS) */
single {
How to get target implementation?????
ApplicationAnalytics
}
}
private val mockAnalyticsModule = module {
single {
MockAnalytics()
}
}
val featureModule = listOf(analyticsModule).ifEmpty {
listOf(mockAnalyticsModule)
}
I have a multimodule application with analytics feature. Since i want to use not only firebase analytics, i need to split the module into api and implementation. Also i will disable some analytics providers by BuildConfig setup. My project dependencies will look something like this:
How to get target implementation in application class?
Initializing a Koin in the application class:
My api class:
My impl class:
Module designation and potential problem area:
Gradle dependency scheme: app:
feature-analytics:
feature-analytics-firebase:
The idea for the implementation is taken from this diagram