Files
m-stecmd/app/src/main/kotlin/com/stec/cmd/config/AppModule.kt

50 lines
1.4 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.stec.cmd.config
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import com.stec.cmd.core.network.NetworkConfig
import com.stec.cmd.core.network.TokenProvider
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
private val Context.configDataStore: DataStore<Preferences> by preferencesDataStore(
name = "stec_cmd_config",
)
/**
* app 壳 Hilt 装配:
* - DataStore 实例;
* - [ConfigRepository] 绑定为 core:network 的 [NetworkConfig] / [TokenProvider]
* 补全 core:network NetworkModule 的依赖图(密钥值由用户配置注入,不入库)。
*/
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Provides
@Singleton
fun provideConfigDataStore(
@ApplicationContext context: Context,
): DataStore<Preferences> = context.configDataStore
}
@Module
@InstallIn(SingletonComponent::class)
abstract class ConfigBindModule {
@Binds
@Singleton
abstract fun bindNetworkConfig(impl: ConfigRepository): NetworkConfig
@Binds
@Singleton
abstract fun bindTokenProvider(impl: ConfigRepository): TokenProvider
}