Skip to content

Commit

Permalink
add DataStoreModule & DataSourceModule
Browse files Browse the repository at this point in the history
  • Loading branch information
eshc123 committed Jul 27, 2024
1 parent 19fabf4 commit 63a41a8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.goalpanzi.mission_mate.core.datastore.di

import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource
import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
abstract class DataSourceModule {

@Binds
abstract fun bindAuthDataSource(
authDataSource: AuthDataSourceImpl
): AuthDataSource
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.goalpanzi.mission_mate.core.datastore.di

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
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 const val AUTH_PREFERENCES = "auth_preferences"

@InstallIn(SingletonComponent::class)
@Module
object DataStoreModule {
@Singleton
@Provides
fun provideAuthPreferencesDataStore(
@ApplicationContext context: Context
): DataStore<Preferences> {
return PreferenceDataStoreFactory.create(
produceFile = { context.preferencesDataStoreFile(AUTH_PREFERENCES) }
)
}
}

0 comments on commit 63a41a8

Please sign in to comment.