I want to set a value to my sub-component builder at the time of building it. If simple Dagger 2 is concerned, we can achieve like following:
@UserScope
@Subcomponent(modules = {UserModule.class, ActivityBuilder.class, NewEditQuotationModule.class})
public interface UserComponent {
NewEditQuotationComponent.Builder getNewEditQuotationComponent();
void inject(UserManager userManager);
@Subcomponent.Builder
interface Builder {
@BindsInstance
Builder user(User user);
UserComponent build();
}}
But In case of Dagger Android, Subcomponent and its associated builder is handled by @ContributesAndroidInjector. Dagger Auto generate Subcomponent and its builder even its implementation with the current context.
I want to set some value at the time of building My Dagger Android Subcomponent. I tried by following approach:
@Subcomponent(modules = NewEditQuotationModule.class)
public interface NewEditQuotationComponent extends AndroidInjector<InquiriesEditNewMainActivity> {
@Subcomponent.Builder
abstract class Builder extends AndroidInjector.Builder<InquiriesEditNewMainActivity> {
@BindsInstance
public abstract Builder setName(@Named("My_Name") String name);
}}
@Module
public abstract class NewEditQuotationModule {
@Binds
@IntoMap
@ActivityKey(InquiriesEditNewMainActivity.class)
abstract AndroidInjector.Factory<? extends Activity>
bindInquiriesEditNewMainActivityInjectorFactory(NewEditQuotationComponent.Builder builder);
}
I tired to build it by following way:
AndroidInjector.Builder androidInjector = MyApplication
.getApplication()
.getAppComponent()
.getApiEndPoint()
.getApiEndPointComponent()
.getUserManager()
.getUserComponent()
.getNewEditQuotationComponent().setName("My Name");
androidInjector.seedInstance(this);
androidInjector.build();
But not succeed. Please let me know
- How can I set some value at the time of building my component?
- Where am I wrong in the previous approach?