I have 2 components: the AppComponent
and the ApiComponent
. I would like to use the dependencies provided by the AppComponent
in the ApiComponent
and in the objects to which the ApiComponent
is injected. So I see the ApiComponent
as a sub component of the AppComponent
. I have declared the AppComponent
as a dependency in the ApiComponent
using the dependecies
directive:
@ApiScope
@Component(dependencies = { AppComponent.class},
modules = { ApiModule.class })
public interface ApiComponent {
void inject(Application application);
void inject(IntentService1 service1);
SampleApi sampleApi();
}
Here is my AppComponent:
@Singleton
@Component (modules = { AppModule.class })
public interface AppComponent {
void (Class2 class2);
Bus bus();
SharedPreferences sharedPreferences();
SampleApplication sampleApplication();
}
The relevant part of my ApiModule looks like this:
@Module
public final class ApiModule {
@Provides
@ApiScope
SampleApi provideSampleApi(Retrofit retrofit) {
return retrofit.create(SampleApi.class);;
}
}
I trigger the injection in onCreate() method of my IntentService1:
@Inject SampleApi sampleApi;
@Override
public void onCreate() {
SampleApplication.get().getApiComponent().inject(this);
}
But I get the following compile error:
SampleApi cannot be provided without an @Provides or @Produce-annotated method
Does anyone have a clue what's going on? I appreciate your help.