miqbaldc
03/14/2022, 1:11 AM:presentation -> :domain <- :data
// in :domain module
class class AnalyticsUseCase @Inject constructor(
private val repository: AnalyticsRepository,
) {
// omitted
}
// in :data module
@InstallIn(SingletonComponent::class)
@Module
interface BindAnalyticsModule {
@get:[Binds]
val AnalyticsRepositoryImpl.analyticsRepo: AnalyticsRepository
}
internal const val DEFAULT_DATASTORE = "_datastore"
@InstallIn(SingletonComponent::class)
@Module
object ProvideAnalyticsModule {
@Singleton
@Provides
fun provideDataStorePreference(
@ApplicationContext context: Context,
): DataStore<Preferences> {
val packageName = context.packageName
val dataStoreName = "$packageName$DEFAULT_DATASTORE"
return PreferenceDataStoreFactory.create(
produceFile = { context.preferencesDataStoreFile(dataStoreName) }
)
}
}
// in :presentation module
@HiltViewModel
class DashboardViewModel @Inject constructor(
private val analyticsUseCase: AnalyticsUseCase,
private val dataStore: DataStore<Preferences>,
)
has no dependency to:presentation
in:data
presentation/build.gradle
miqbaldc
03/14/2022, 1:15 AMmiqbaldc
03/14/2022, 1:56 AMThis seems not possible especially since depends on, after trying it outhilt-android
miqbaldc
03/14/2022, 1:56 AMhilt-core
(for dependency that not requires android related)Javier
03/14/2022, 9:07 AMmiqbaldc
03/15/2022, 5:00 AMhilt-android
& datastore-preferences
(w/o -core
suffix, has android dependencies) fails to compile.
Any references or samples to lookup first, if there’s any?Javier
03/15/2022, 9:06 AMmiqbaldc
03/15/2022, 9:44 AMJavier
03/15/2022, 9:51 AMmiqbaldc
03/15/2022, 12:17 PMJavier
03/15/2022, 12:32 PMmiqbaldc
03/15/2022, 12:55 PMmiqbaldc
03/24/2022, 11:09 AMJavier
03/24/2022, 11:16 AMmiqbaldc
03/24/2022, 11:26 AMJavier
03/24/2022, 11:38 AMJavier
03/24/2022, 11:39 AMJavier
03/24/2022, 11:40 AMJavier
03/24/2022, 11:41 AMmiqbaldc
03/24/2022, 11:45 AMlegacy
to presentation
nowmiqbaldc
03/24/2022, 11:47 AMpresentation
module? e.g:
| domain // kotlin library
| data:analytics // android library
| presentation // contains dagger moduler provider etc, android library
| app // android application
Javier
03/24/2022, 11:53 AMJavier
03/24/2022, 11:53 AMJavier
03/24/2022, 11:54 AMJavier
03/24/2022, 11:56 AMJavier
03/24/2022, 11:56 AMmiqbaldc
03/24/2022, 11:58 AMapp
modules behaves as presentation
miqbaldc
03/24/2022, 11:59 AMapp adds as dependencies the three modulesThis part seems inevitable right? I tho’ we can prevent our application to have import from
data
layerJavier
03/24/2022, 12:01 PMJavier
03/24/2022, 12:02 PMmiqbaldc
03/24/2022, 12:05 PMJavier
03/24/2022, 12:14 PMJavier
03/24/2022, 12:14 PMJavier
03/24/2022, 12:14 PMmiqbaldc
03/25/2022, 7:19 AM:app
needs to depends on different data-layer implementation :data:<sub module>
, e.g:
:data // common or core
:data:analytics // implementation details of analytics tracker
dependency:
:presentation -> :domain <- :data <- :data:analytics // like this, I presume?
:presentation <- :data:analytics // avoid doing this?
Based on your suggestions here (cmiiw):
:app -> :domain
:app -> :data
:app -> :data:analytics
:app -> :presentation
Javier
03/25/2022, 9:30 AMJavier
03/25/2022, 9:30 AMmiqbaldc
03/26/2022, 7:52 AM:app
required to add everything (:data:<submodule(s)>
) as dependencies (using api
?)
even tho’ there’s no direct import / usage in :app
as long all of the @Provider
(for concrete impl.) are exist inside :data:<submodule>
(and :data
)
in order for dagger to compiled properly?
cmiiwmiqbaldc
03/26/2022, 8:00 AMif data modules are adding as dependency other data modules using api,does this means (see image attachment by order): 1️⃣ 2️⃣ 3️⃣
Javier
03/26/2022, 11:40 AMJavier
03/26/2022, 11:41 AMmiqbaldc
03/30/2022, 2:56 AM// interface in :data (a kotlin library)
interface DataSource {}
// and injected by
class SomeClassDataStore @Inject constructor(private val dataSource: DataSource)
// concrete implementation & DI provider in :data:sharedprefs
// (is an android library)
class SharedPrefsManager : DataSource {}
@InstallIn(SingletonComponent::class)
@Module
interface BindSharedPrefsModule {
@get:[Binds DataStorePreferences]
val SharedPrefsManager.sharedPrefsManager: DataSource
}
as :data
doesn’t have direct dependencies to :data:sharedprefs
, meanwhile doing that will resulting in a cyclic dependenciesmiqbaldc
03/30/2022, 3:00 AMSomeClassDataStore
to another modules’ that has dependencies on both: :data
& :data:sharedprefs
in this case?Javier
03/30/2022, 10:02 AMJavier
03/30/2022, 10:02 AMJavier
03/30/2022, 10:03 AMJavier
03/30/2022, 10:03 AMmiqbaldc
03/30/2022, 10:31 AMwhat you app module is adding as dependencies?
// app/build.gradle
implementation(project(":data"))
implementation(project(":data:analytics"))
implementation(project(":data:shared-preferences"))
miqbaldc
04/13/2022, 6:47 AM:app -> :dagger-bridge
:dagger-bridge -> :data
:dagger-bridge -> :data:sharedprefs
:dagger-bridge -> :domain
Javier
04/13/2022, 9:50 AM