简体   繁体   中英

Dagger 2.10 add abstract module

I'm doing what Jeff Bowman described at Dagger 2.10 Android subcomponents and builders and it works perfectly fine. Now I want to add abstract module with only @Binds How can I do this?

After I override seedInstance my activity is not visible inside that abstract module so I probably should add something to seedInstance

If you your module is an abstract class or interface, or it has a public parameterless constructor, you can just add it to your module list without supplying an instance and everything should work just fine. This means:

@Subcomponent(modules = {YourAbstractModule.class /*, ... */})
public interface YourActivitySubcomponent extends AndroidInjector<YourActivity> {

or using @ContributesAndroidInjector :

@ContributesAndroidInjector(modules = {YourAbstractModule.class /*, ... */})
@YourScope
abstract YourActivity bindYourActivityInjector();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM