Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependent Component BindsInstance Failing #72

Open
ArjunChinya opened this issue Mar 3, 2018 · 1 comment
Open

Dependent Component BindsInstance Failing #72

ArjunChinya opened this issue Mar 3, 2018 · 1 comment

Comments

@ArjunChinya
Copy link

ArjunChinya commented Mar 3, 2018

Hi Fabio,

Here is my Component and Dependent Component

Main Component
@AppScope
@component(modules = {AndroidInjectionModule.class, ActivityModule.class}, dependencies = RepositoryComponent.class)
public interface ApplicationComponent {
void inject(Application application);
}

Dependent Component
@singleton
@component(modules = RepositoryModule.class)
public interface RepositoryComponent {
ApiService apiService();

@Component.Builder
interface Builder {
RepositoryComponent build();
@BindsInstance
Builder context(@nAmed("ApplicationContext") Context context);
}
}

Custom Dagger Rule
public class DaggerRule extends DaggerMockRule {

public DaggerRule() {
super(ApplicationComponent.class);
customizeBuilder(new BuilderCustomizer<RepositoryComponent.Builder>() {
@OverRide
public RepositoryComponent.Builder customize(RepositoryComponent.Builder builder) {
Application application = (Application) RuntimeEnvironment.application;
return builder.context(application);
}
});
addComponentDependency(RepositoryComponent.class, new RepositoryTestModule());
set(component -> {
Application application = (Application) RuntimeEnvironment.application;
application.setApplicationComponent(component);
});
}
}

I seen an error saying : java.lang.IllegalStateException: android.content.Context must be set even though I have set context using customizeBuilder. I may be doing something wrong can you please help.

@fabioCollini
Copy link
Owner

Hi, why did you define the context method in the RepositoryComponent builder instead of the ApplicationComponent builder? I have never tried this configuration but I think it's the reason of your problem. Can you try to modify the code?
Thanks for your report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants