Dagger2 : How to use @Provides and @Binds in same module

前端 未结 4 2271
无人及你
无人及你 2020-12-18 18:20

I\'m using the new Dagger2 (ver 2.11) and I\'m using the new features like AndroidInjector, and ContributesAndroidInjector. I have an activity subc

4条回答
  •  甜味超标
    2020-12-18 18:47

    A little addition to Jeff's solution above:

    you may create inner interface instead of static inner class, like this:

    @Module(includes = AppModule.BindsModule.class)
    public class AppModule {
        // usual non-static @Provides
        @Provides
        @Singleton
        Checkout provideCheckout(Billing billing, Products products) {
            return Checkout.forApplication(billing, products);
        }
        // interface with @Binds
        @Module
        public interface BindsModule {
            @Binds
            ISettings bindSettings(Settings settings);
        }
    }
    

提交回复
热议问题