Last active
September 28, 2019 09:57
-
-
Save ininmm/d95cbace1b16ad13ed2942cbba5787ef to your computer and use it in GitHub Desktop.
DataModule 的 整理
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
@Module(includes = [DatabaseModuleBinds::class]) | |
class DatabaseModule { | |
@Singleton | |
@Provides | |
fun provideDataBase(context: Context): ToDoRoomDatabase { | |
return Room.databaseBuilder( | |
context.applicationContext, | |
ToDoRoomDatabase::class.java, | |
"Task.db" | |
).build() | |
} | |
@Provides | |
fun provideTasksDao(db: ToDoDatabase) = db.tasksDao() | |
} | |
@Module | |
abstract class DatabaseModuleBinds { | |
@Binds | |
abstract fun bindToDoDatabase(roomDatabase: ToDoRoomDatabase): ToDoDatabase | |
} |
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
@Module( | |
includes = [ | |
DataSourceModule::class, | |
RepositoryBinds::class, | |
DatabaseModule::class, | |
NetworkModule::class | |
] | |
) | |
class DataModule { | |
@Qualifier | |
@Retention(AnnotationRetention.RUNTIME) | |
annotation class TasksLocalData | |
@Qualifier | |
@Retention(AnnotationRetention.RUNTIME) | |
annotation class TasksRemoteData | |
} |
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
@Module(includes = [DataSourceBinds::class]) | |
class DataSourceModule { | |
@DataModule.TasksRemoteData | |
@Provides | |
fun provideTasksRemoteDataSource(): TasksDataSource { | |
return TasksRemoteDataSource | |
} | |
} | |
@Module | |
abstract class DataSourceBinds { | |
@DataModule.TasksLocalData | |
@Binds | |
abstract fun bindToTasksLocalData(tasksLocalDataSource: TasksLocalDataSource): TasksDataSource | |
} |
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
@Module | |
abstract class RepositoryBinds { | |
@Singleton | |
@Binds | |
abstract fun bindToTasksRepository(tasksRepository: TasksRepository): ITasksRepository | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment