-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finalised data-layer-added dependency injection module in di package
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package budgetTracker.app.di | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import budgetTracker.app.data.TransactionDao | ||
import budgetTracker.app.data.TransactionDatabase | ||
import budgetTracker.app.data.repository.DataStoreRepositoryImpl | ||
import budgetTracker.app.data.repository.TransactionRepositoryImpl | ||
import budgetTracker.app.domain.repository.DataStoreRepository | ||
import budgetTracker.app.domain.repository.TransactionRepository | ||
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 | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object BudgetModule { | ||
|
||
|
||
@Provides | ||
@Singleton | ||
fun provideDataStoreRepository(@ApplicationContext context: Context):DataStoreRepository{ | ||
return DataStoreRepositoryImpl(context) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesTransactionDao(database: TransactionDatabase) = database.transactionDao | ||
|
||
@Provides | ||
@Singleton | ||
fun providesTransactionRepository(transactionDao: TransactionDao):TransactionRepository{ | ||
return TransactionRepositoryImpl(transactionDao) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesTransactionDatabase(@ApplicationContext context: Context):TransactionDatabase{ | ||
return Room.databaseBuilder(context,TransactionDatabase::class.java,"transactionDB") | ||
.fallbackToDestructiveMigration() | ||
.build() | ||
} | ||
|
||
|
||
} |