/
alexm
/
Notes
Обзор
Документация
Войти
/
alexm
/
Notes
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/src/main/java/com/alex/notes/di/DataModule.kt
49 строк
1 KB
bolschoy
5.2
01 авг 2025, 21:17
01 авг 2025, 21:17
1cb232e
Код
Авторство
О чём код?
package com.alex.notes.di import android.content.Context import androidx.room.Database import androidx.room.Room import com.alex.notes.data.NotesDao import com.alex.notes.data.NotesDatabase import com.alex.notes.data.NotesRepositoryImpl import com.alex.notes.domain.NotesRepository 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 @Module @InstallIn(SingletonComponent::class) interface DataModule { @Singleton @Binds fun bindNotesRepository( impl: NotesRepositoryImpl ): NotesRepository companion object{ @Singleton @Provides fun provideDatabase( @ApplicationContext context: Context ): NotesDatabase{ return Room.databaseBuilder( context=context, klass = NotesDatabase::class.java, name = "notes.db" ).fallbackToDestructiveMigration(dropAllTables = true).build() } @Singleton @Provides fun provideNotesDao( database: NotesDatabase ): NotesDao { return database.notesDao() } } }