【发布时间】:2016-11-17 08:59:02
【问题描述】:
我正在尝试通过这个 android-architecture 示例代码:- https://github.com/googlesamples/android-architecture/tree/todo-mvp-dagger/todoapp
我也已阅读此用户指南 - https://google.github.io/dagger/users-guide
这是TasksRepositoryComponent
中的代码@Singleton
@Component(modules = {TasksRepositoryModule.class, ApplicationModule.class})
public interface TasksRepositoryComponent {
TasksRepository getTasksRepository();
}
扩展 Application 的 ToDoApplication 在 onCreate() 中有此代码 -
mRepositoryComponent = DaggerTasksRepositoryComponent.builder()
.applicationModule(new ApplicationModule((getApplicationContext())))
.build();
有些东西我听不懂:-
为什么 TasksRepositoryComponent 不像应用程序中的其他组件那样具有 inject() 方法?
为什么 ToDoApplication 在 build() 之前不调用 DaggerTasksRepositoryComponent 中的方法 tasksRepositoryModule()?为什么不需要呢?
有没有什么地方可以找到使用 dagger2 时要遵守的规则的良好文档?
【问题讨论】:
-
这些可能会有所帮助:stackoverflow.com/questions/40562481/… 和 stackoverflow.com/questions/40545075/dagger2-and-android/… 虽然我还没有使用很多东西(
@IntoSet、@Binds等)