Skip to content

Commit 8ab4aa6

Browse files
Add Dagger Module
1 parent 65e731f commit 8ab4aa6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

0 commit comments

Comments
 (0)