In ProfileExtendedPresenter when I only put the view (first parameter) in the Constructor, it works. With the second energyProfileRepository I get the error below:
Error message:
ProfileExtendedComponent.inject(ProfileExtendedActivity)] EnergyProfileRepository cannot be provided without an @Inject constructor or from an @Provides-annotated method.
EnergyProfileRepository is injected at
RepositoryModule.energyProfileRepository(energyProfileRepository)
Repository<EnergyProfile> is injected at
ProfileExtendedPresenter.<init>(…, energyProfileRepository)
ProfileExtendedPresenter is injected at
ProfileExtendedModule.presenter(presenter)
ProfileExtendedMvp.Presenter is injected at
ProfileExtendedActivity.presenter
.ProfileExtendedActivity is injected at
.ProfileExtendedComponent.inject(activity)
I think it has something to do with the presenter. But the scope of the injection is Activity. This is correct I think? I've added all files but not sure if this is too much, because I don't know where the problem exactly occurs.
@Singleton
@Component(modules = {AppModule.class, RepositoryModule.class})
public interface AppComponent {
ProfileExtendedComponent plus(ProfileExtendedModule module);
}
@Module
public class AppModule {
@Provides
@AppContext
@Singleton
public Context context() {
return Application.getInstance();
}
@Provides
@Singleton
public Resources resources(@AppContext Context context) {
return context.getResources();
}
}
@Module
public class ProfileExtendedModule {
private ProfileExtendedMvp.View view;
public ProfileExtendedModule(ProfileExtendedMvp.View view) {
this.view = view;
}
@Provides
public ProfileExtendedMvp.View view() {
return view;
}
@Provides
public ProfileExtendedMvp.Presenter presenter(ProfileExtendedPresenter presenter) {
return presenter;
}
}
@Module
public class RepositoryModule {
@Provides
@Singleton
public Repository<EnergyProfile> energyProfileRepository(EnergyProfileRepository energyProfileRepository) {
return energyProfileRepository;
}
}
@Subcomponent(modules = {ProfileExtendedModule.class})
public interface ProfileExtendedComponent {
void inject(ProfileExtendedActivity activity);
}
public class ProfileExtendedActivity extends BaseActivity implements ProfileExtendedMvp.View {
@Inject
ProfileExtendedMvp.Presenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injectDependencies(Application.getInstance().getAppComponent());
presenter.init();
}
}
public class ProfileExtendedPresenter implements ProfileExtendedMvp.Presenter {
ProfileExtendedMvp.View view;
Repository<EnergyProfile> energyProfileRepository;
@Inject
public ProfileExtendedPresenter(ProfileExtendedMvp.View view, Repository<EnergyProfile> energyProfileRepository) {
this.view = view;
this.energyProfileRepository = energyProfileRepository;
}
}
public interface ProfileExtendedMvp {
interface View extends Mvp.View {
}
interface Presenter extends Mvp.Presenter {
void init();
}
}
public class EnergyProfileRepository implements Repository<EnergyProfile> {
@Override
public Observable<EnergyProfile> fetch() {
return null;
}
}
public interface Repository<T> {
Observable<T> fetch();
}
public class EnergyProfile implements Cacheable {
@Json(name = "availableType")
private Map<String, String> houseTypesContainer;
}
public interface Cacheable {
void setCached();
boolean isCached();
}