Android Dagger2 @Component依赖多个Module

Dagger2中Component可以依赖单个Module,写法如下

1
2
3
4
5
6
7
8
9
10
@Component(modules = MainModule.class)
public interface MainActivityComponent {
void inject(MainActivity activity);
}

// 或者
@Component(modules = {MainModule.class})
public interface MainActivityComponent {
void inject(MainActivity activity);
}

Click and drag to move

也可以依赖多个Module,如下所示

1
2
3
4
5
6
7
@Component(modules = {
MainModule.class,
TeacherModule.class
})
public interface MainActivityComponent {
void inject(MainActivity activity);
}

Click and drag to move