应用场景:将有参数的构造函数的实例注入到目标类中
如:依赖类:

module中 要提供对象,还有提供参数
如下:

对应的Component接口:

还有原来的套路,我们rebuild一下,生成java文件
注意这里。我们不能直接使用DaggerSellMoeComponent.create()
为什么呢,查看生成的DaggerSellMoeComponent.java文件,发现没有create()这个方法
那么该如何使用呢, 我们来分析一下:
我们先看一下inject(MainActivity mainActivity)

从1-->2--->3,我们发现我们需要sellMoeModule这个实例,那么sellMoeModule是怎么获取到引用的呢?
我们会发现如下代码:

显然是通过构造函数中实现将SellMoeModule的实例sellMoeModule注入到DaggerSellMoeComponent这个类中。那么这个构造函数是从哪里调用的呢?

到这里你就会发现,我们必须手动调用这个Builder内部类中的sellMoeModule这个构造函数
所以使用就很简单了

注意此处其他的对象注入到目标类的流程和前面的几篇文章的套路基本上一致
网友评论