为什么没有@Provides注释的方法就无法提供java.lang.Boolean。当我实际提供时?

问题描述 投票:0回答:1

这里是包含另一个模块FeatureXModule的模块

interface FragmentModule {
@FragmentScope
@ContributesAndroidInjector(
    modules = {
             FeatureXModule.class
    })

  @Binds
  @Group
  @IntoSet
  IntentGroup bindDefaultGroup(DefaulGroup group);

 @Binds
 @Group
 @IntoSet
 IntentGroup bindGroup(Group group);

}

Group类看起来像这样

class Group{

@Inject
public Group(@IsEnabled boolean isEnabled) {}
 }

这是第一个模块所依赖的下一个模块

interface FeatureXModule {
@Provides
@IsEnabled
static boolean provideXEanbled() {
    return true;// TODO: change it
}
}

构建此库时,如果没有@Provides注释的方法,将无法提供.IsEnabled java.lang.Boolean。

而且有趣的是,当我将bind方法移至应用程序构建的第二个模块时这是怎么了

android dagger-2 dagger
1个回答
0
投票

模块是否组成?换句话说,一个模块是否知道另一个模块的绑定?

执行此操作的方法是使用@Includes

@Module(includes = {FeatureModule.class})
interface FeatureXModule {

请参见this question以获取更多详细信息。

或者,一个组件可以具有来自多个模块的绑定:

@Component(modules={Module1.class, Module2.class})
© www.soinside.com 2019 - 2024. All rights reserved.