首先,我用谷歌搜索了几件事,但是无法做到 . 我有两个适用于app的组件,另一个用于 DataBinding
,如下所示:
AppComponent
@Singleton
@Component(modules = {AndroidSupportInjectionModule.class,
AppModule.class})
public interface AppComponent extends AndroidInjector<FanseeApp> {
@Override
void inject(FanseeApp instance);
@Component.Builder
interface Builder {
@BindsInstance
AppComponent.Builder application(Application application);
AppComponent build();
}
}
BindingComponent
@DataBinding
@Component(dependencies = AppComponent.class, modules = {BindingModule.class, AppModule.class})
public interface BindingComponent extends DataBindingComponent {}
我想对两个组件使用 SharedPreferences
. 它被放置在AppModule中但是,我收到以下错误:
[Dagger / MissingBinding]如果没有@Inject构造函数或@ Provide-annotated方法,则无法提供android.app.Application . public interface BindingComponent extends DataBindingComponent {} ^ android.app.Application注入com.nuhkoca.fansee.di.module.ContextModule.bindsContext(application)android.content.Context注入com.nuhkoca.fansee.di.module . AppModule.provideSharedPreference(context)android.content.SharedPreferences注入com.nuhkoca.fansee.util.PreferenceUtil(sharedPreferences)com.nuhkoca.fansee.util.PreferenceUtil注入com.nuhkoca.fansee.di.module.BindingModule . bindsSpannableTextBindingAdapter(preferenceUtil)com.nuhkoca.fansee.binding.SpannableTextBindingAdapter在androidx.databinding.DataBindingComponent.getSpannableTextBindingAdapter()中提供
如何使用具有多个组件的相同模块?非常感谢提前!