¡¡¡¡ÏÈ¿´¿´.create·½·¨£¬¿ÉÒÔ¿´µ½¾ÍÊǺܼòµ¥µÄnew Teacher_MembersInjector £¬Ï൱ÓÚ³õʼ»¯ÁËһЩ³ÉÔ±±äÁ¿studentProvider £¬ÖÁÓÚstudentProvider ÊÇʲô£¬´Ó×ÖÃæµÄÒâ˼ÉÏÀ´¿´ÊÇÎÒÃÇstudentµÄÌṩÕߣ¬ÄÇôÊÇʱºòÎÒÃǾÍÔÙÀ´¿´¿´Student_Factory.create()·½·¨ÁË£¬ÒòΪÊÇÕâ¸öÀàÌṩÁËstudentProvider ¶ÔÏó
package com.qianmo.rxjavatext; import dagger.internal.Factory; import javax.annotation.Generated; @Generated( value = "dagger.internal.codegen.ComponentProcessor", comments = "https://google.github.io/dagger" ) public enum Student_Factory implements Factory<Student> { INSTANCE; @Override public Student get() { return new Student(); } public static Factory<Student> create() { return INSTANCE; } }
¡¡¡¡ÎѲݣ¬Çë¿´get·½·¨ÖÐµÄ ¡°new Student()¡±´úÂ룬Õâ²»¾ÍÊÇÎÒÃǵÄstudent¶ÔÏóµÄ´´½¨ÂÔÀ´ÄãÔÚÕâÀÔÙ¿´Ò»ÏÂÔÚÄÄÀïµ÷ÓÃÎÒÃǵÄstudentProvider.get·½·¨Äõ½´´½¨µÄStudent¶ÔÏó£¬ÕâʱºòÇë¿´Teacher_MembersInjector.injectMembers()·½·¨£¬¾ßÌå´úÂëÈçÏ£º
@Override public void injectMembers(Teacher instance) { if (instance == null) { throw new NullPointerException("Cannot inject members into a null reference"); } instance.student = studentProvider.get(); }
¡¡¡¡¿´µ½ÎÒÃǵ¹ÊýµÚ¶þÐÐÁËû£¬ÔÚÕâÀïÎÒÃÇÄõ½teacher¶ÔÏó£¬ÉèÖÃËüµÄ³ÉÔ±±äÁ¿student¡£ok£¬µ½ÕâÀïÎÒÃǾͶ®ÁË£¬Õû¸öÂß¼¾ÍÈ«²¿Í¨ÁË£¬Ê×ÏÈDaggerTeacherComponent.builder().build()Ö´ÐÐÍêÔÚStudent_FactoryÖд´½¨ºÃÁËstudent¶ÔÏó£¬È»ºóÔÚµ÷ÓÃinjectA(this)·½·¨£¬½«´´½¨µÄstudent¶ÔÏó·ÅÖõ½teacher¶ÔÏóÖеÄstudentÊôÐÔÉÏ¡£
¡¡¡¡OK£¬µ½ÕâÀïÎÒÃǾͼòµ¥µÄÁ˽âÁËDagger2µÄʹÓÃÁË£¬Ð´µ½ÕâÀïƪ·ùÒѾ±È½Ï³¤ÁË£¬ËùÒÔÎÒ´òËãÓÃÈýƪÎÄÕÂÀ´ºÍ´ó¼Ò³Ô͸Dagger2£¬ºÍ´ó¼ÒÒ»Æð´ÓÔ´ÂëÈë¿Óµ½Ìø¿Ó£¬×îºó£¬»¹ÓÐÒ»¸öºÜ¹Ø¼üÊÂÍü˵ÁË£º×î½ü´òËã´ÇÖ°»Ø±±¾©£¬ÓÐûÓдóÉñͬѧÍƼö¹¤×÷£¬´ø´øСµÜ°¡
¡¡