Guowei Lv

1 minute read

Components can have multiple Modules. So if you have huge Modules that provide tons of services, it is good to split it up.

Let’s create a UseCaseModule to hanle all the UseCases.

@Module
class UseCasesModule {

    @Provides
    fun fetchQuestionsUseCase(stackOverflowApi: StackoverflowApi) = FetchQuestionsUseCase(stackOverflowApi)

    @Provides
    fun fetchQuestionDetailsUseCase(stackOverflowApi: StackoverflowApi) = FetchQuestionDetailsUseCase(stackOverflowApi)
}

Some dagger conventions:

  1. Components can use more than 1 module.
  2. Modules of the same Component share the same object-graph.
  3. Dagger automatically instantiate modules with no argument constructor.
comments powered by Disqus