Dagger只应注入MainApplication类,其他任何依赖项都没有:
的build.gradle
dependencIEs { ... // Dagger compile 'com.Google.dagger:dagger:2.10' compile 'com.Google.dagger:dagger-androID:2.10' annotationProcessor 'com.Google.dagger:dagger-compiler:2.10' // Fix for incompatible library versions when adding dagger-androID and having espresso-core:2.2.2 in tests androIDTestCompile 'com.Google.code.findBUGs:Jsr305:3.0.1'}
MainApplication.java
public class MainApplication extends Application implements HasdispatchingActivityInjector { @Inject dispatchingAndroIDInjector<Activity> dispatchingAndroIDInjector; @OverrIDe public voID onCreate() { super.onCreate(); DaggerMainApplicationComponent.create(); // DaggerMainApplicationComponent.create().inject(this); does not work - no inject(...) method! } @OverrIDe public dispatchingAndroIDInjector<Activity> activityInjector() { return dispatchingAndroIDInjector; }}
MainApplicationComponent.java
@Component(modules = AndroIDInjectionModule.class)public interface MainApplicationComponent {}
自动生成的DaggerMainApplicationComponent.java:
public final class DaggerMainApplicationComponent implements MainApplicationComponent { private DaggerMainApplicationComponent(Builder builder) { assert builder != null; } public static Builder builder() { return new Builder(); } public static MainApplicationComponent create() { return new Builder().build(); } public static final class Builder { private Builder() {} public MainApplicationComponent build() { return new DaggerMainApplicationComponent(this); } }}
我是Dagger的新手,有很多资源,但很多人用过时的Dagger库描述DI.我的实施有什么问题?
我还发现了一个名为MainApplication_MembersInjector的自动生成的类…我自己必须使用它吗?
@Component(modules = AndroIDInjectionModule.class)public interface MainApplicationComponent { voID inject(dispatchingAndroIDInjector dispatchingAndroIDInjector);}总结
以上是内存溢出为你收集整理的Dagger 2 Android应用程序组件缺少注入方法全部内容,希望文章能够帮你解决Dagger 2 Android应用程序组件缺少注入方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)