File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
app/src/main/java/com/codexo/notes/core Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ package com.codexo.notes.core
2+
3+ import android.content.Context
4+ import androidx.room.Room
5+ import com.codexo.notes.data.NoteDao
6+ import com.codexo.notes.data.NoteDatabase
7+ import dagger.Module
8+ import dagger.Provides
9+ import dagger.hilt.InstallIn
10+ import dagger.hilt.android.qualifiers.ApplicationContext
11+ import dagger.hilt.components.SingletonComponent
12+ import javax.inject.Singleton
13+
14+ @Module
15+ @InstallIn(SingletonComponent ::class )
16+ object DatabaseModule {
17+
18+ @Singleton
19+ @Provides
20+ fun provideDatabase (@ApplicationContext applicationContext : Context ): NoteDatabase {
21+ return Room .databaseBuilder(
22+ applicationContext,
23+ NoteDatabase ::class .java,
24+ " notes_db"
25+ ).fallbackToDestructiveMigration().build()
26+ }
27+
28+ @Provides
29+ fun provideNoteDao (noteDatabase : NoteDatabase ): NoteDao = noteDatabase.noteDao()
30+ }
You can’t perform that action at this time.
0 commit comments