1

I'm using com.google.dagger:dagger-android 2.24 (not the stock dagger) and couldn't figure out out how to use @BindsInstance for runtime injection. Any help would be appreciated!

Application class

public class BaseApplication extends DaggerApplication {

    @Override
    protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
        return DaggerAppComponent.factory().create(this);
    }
}

AppComponent

@Singleton
@Component(modules = {
        AndroidSupportInjectionModule.class
})

public interface AppComponent extends AndroidInjector<BaseApplication> {

    @Component.Factory
    interface Factory {
        AppComponent create(@BindsInstance Application application);
    }
}

The subcomponent that I want to create, but don't know how/where to set it up

@Subcomponent(modules = PlayersModule.class)
public interface PlayersComponent extends AndroidInjector<PlayersActivity> {

    @Subcomponent.Factory
    interface Factory {
        PlayersComponent create(@BindsInstance @Named("players_list") List<Player> playerList,
                                  @BindsInstance @Named("number_of_teams") int numberOfTeams);
    }
}
mco
  • 1,809
  • 15
  • 31

0 Answers0