这是包含另一个模块的模块FeatureXModule
interface FragmentModule {
@FragmentScope
@ContributesAndroidInjector(
modules = {
FeatureXModule.class
})
@Binds
@Group
@IntoSet
IntentGroup bindDefaultGroup(DefaulGroup group);
@Binds
@Group
@IntoSet
IntentGroup bindGroup(Group group);
}
组类的位置看起来像这个
class Group{
@Inject
public Group(@IsEnabled boolean isEnabled) {}
}
这是下一个模块,第一个模块取决于
interface FeatureXModule {
@Provides
@IsEnabled
static boolean provideXEanbled() {
return true;// TODO: change it
}
}
当我构建它时,我会收到.IsEnabled java.lang.Boolean如果没有@Providers注释的方法就无法提供。
有趣的是,当我将bind
方法移动到应用程序构建的第二个模块时这里怎么了?
模块是组合的吗?换句话说,一个模块知道另一个模块的绑定吗?
这样做的方法是使用@Includes
:
@Module(includes = {FeatureModule.class})
interface FeatureXModule {
请参阅此问题了解更多详细信息。
或者,一个组件可以具有来自多个模块的绑定:
@Component(modules={Module1.class, Module2.class})