Android 父组件中是否提供了上下文?

Android 父组件中是否提供了上下文?,android,dagger-2,Android,Dagger 2,使用dagger 2,我创建了一个应用程序生命周期范围图和一个活动生命周期范围图。在活动图中,我想为所有活动提供相同的毕加索实例 应用模块: @Module public final class AppModule { Application application; public AppModule(Application application) { this.application = application; } @Provides

使用dagger 2,我创建了一个应用程序生命周期范围图和一个活动生命周期范围图。在活动图中,我想为所有活动提供相同的毕加索实例

应用模块:

@Module
public final class AppModule {
    Application application;

    public AppModule(Application application) {
        this.application = application;
    }

    @Provides
    @Singleton
    Context provideContext() {
        return application;
    }
}
应用组件:

@Component(modules = {AppModule.class})
@Singleton
public interface AppComponent {
    ActivityComponent activityComponent(ActivityModule activityModule);
}
@Subcomponent(modules = ActivityModule.class)
@PerActivity
public interface ActivityComponent {
    FragmentComponent fragmentComponent(FragmentModule fragmentModule);
}
活动模块:

@Module
public final class ActivityModule {
    @Provides
    @Singleton
    Picasso providePicasso(Context context, OkHttpClient client) {
        return new Picasso.Builder(context).downloader(new 
OkHttp3Downloader(client)).build();
}
活动组件:

@Component(modules = {AppModule.class})
@Singleton
public interface AppComponent {
    ActivityComponent activityComponent(ActivityModule activityModule);
}
@Subcomponent(modules = ActivityModule.class)
@PerActivity
public interface ActivityComponent {
    FragmentComponent fragmentComponent(FragmentModule fragmentModule);
}
ActivityModule providePicasso中发生错误,抱怨如果没有@Providers注释方法,则无法提供上下文


ActivityComponent是AppComponent的子组件,它应该可以访问其父组件中的所有内容,AppModule通过provideContext提供上下文,不是吗?

您的子组件的范围是
@PerActivity
,但在其中,您将毕加索作为一个
@Singleton
从更广的范围提供。如果您想将毕加索作为一个
@Singleton
提供,您可以在
AppComponent
级别上进行,您的子组件的作用域是
@PerActivity
,但在它中,您将毕加索作为一个
@Singleton
从更广的范围提供。如果您想将毕加索作为
@Singleton
提供,您可以在
AppComponent