Build Dagger for Multi-module Android project

看了一个人讲 multi module 和 dagger的,突然发现就是和我们现在做得很像。

比如有这么样的module结构

– core 人人都要它 – moduleA 需要core才能建立A功能 – moduleB 需要core才能建立B功能 – app 构建apk的module,需要core 才能建立基本功能

那么就在

-- core 里建立一个 CoreComponent

-- moduleA 
    FeatureComponentA.builder().coreComponent(DI.singleton.holdsCoreComponent).build()

-- moduleB
    FeatureComponentB.builder().coreComponent(DI.singleton.holdsCoreComponent).build()

十分像我们现在做的AppComponent和ScreenComponent的结构。连有一个Singleton 拿着CoreComponent都一样。我的DIComponent.modelComponent不正是这样的原理吗。

我们在什么时候真正build这个core呢,还是从Application起来的时候,也就是在app module里面。

  • 以上提到的module都不是 @Module,而是android project module