Skip to content

Instantly share code, notes, and snippets.

@digitalbuddha
Created August 2, 2017 19:30
Show Gist options
  • Save digitalbuddha/f32d7d2213e7a1b0db6dfa7096d1c0e0 to your computer and use it in GitHub Desktop.
Save digitalbuddha/f32d7d2213e7a1b0db6dfa7096d1c0e0 to your computer and use it in GitHub Desktop.
public class ToDoApplication extends Application implements HasActivityInjector {
@Inject
DispatchingAndroidInjector<Activity> activityInjector;
@Override
public void onCreate() {
super.onCreate();
DaggerAppComponent.builder().application(this).build().inject(this);
}
@Override
public AndroidInjector<Activity> activityInjector() {
return activityInjector;
}
}
@Singleton
@Component(modules = { ActivityBindingModule.class, AndroidSupportInjectionModule.class})
public interface AppComponent {
void inject(ToDoApplication application);
@Component.Builder
interface Builder {
@BindsInstance
AppComponent.Builder application(Application application);
AppComponent build();
}
}
@Module
abstract class ActivityBindingModule {
@PerActivity
@ContributesAndroidInjector
abstract OtherActivity tasksActivity();
}
public class OtherActivity extends AppCompatActivity implements HasSupportFragmentInjector {
@Inject
DispatchingAndroidInjector<Fragment> fragmentInjector;
@Override
public AndroidInjector<Fragment> supportFragmentInjector() {
return fragmentInjector;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment