Dagger 2.10 Android subcomponents and builders

前端 未结 2 1745
囚心锁ツ
囚心锁ツ 2020-11-27 13:41

Using the new (in 2.10) dagger.android classes, I\'m trying to inject things using a Subcomponent that depends on other Modules, and, therefore, has a Builder with setters f

2条回答
  •  -上瘾入骨i
    2020-11-27 14:08

    that does work, but it's unnecessary. the seedInstance method provides the activity instance into the graph, so you can have MyActivityModule with no state, and just request MyActivity in your @Provides methods.

    class MyActivityModule {
      @Provides
      static SomethingDerivedFromMyActivity providesMethod(MyActivity myActivity) {
        return myActivity.somethingDerived();
      }
    }
    

    Doing this saves the module instance and allows the generated factories to be leaner.

    from https://github.com/google/dagger/issues/615.

提交回复
热议问题