首页
学习
活动
专区
工具
TVP
发布
您找到你想要的搜索结果了吗?
是的
没有找到

Dagger2 入门解析

SubComponent 事实上,到这里dagger的用法对于服务端来说已经足够了。通过module的连接特性可以定义IoC容器范围,再结合dropwizard,就和springboot一样了。...然而,毕竟dagger2是为了Android而打造的,为了适应其复杂的继承体系和生命周期的限制,dagger提供了SubComponent模型。也就是子组件。...对于Subcomponent的作用,大概有两点: 1)继承扩展功能并绑定生命周期,2)封装。 继承体现在subcomponent可以使用parent的module,共享其生命周期。...封装则是因为但其他人都不可以使用subcomponent的依赖,只能使用subcomponent本身。也就是parent里的Component不能调用subcomponent里的module。...暂时没能理解subcomponent和scope的使用,感觉有些复杂。

1.4K120

Android | dagger细枝篇

@Subcomponent Subcomponent即子组件,可以将父组件的能力继承过来,同时扩展自己的能力。...现在已经有了@Component的CarGraph来造车,我们可以建一个@Subcomponent的WheelGraph来造轮胎,(虽是轮胎图纸,但也有造车之心) @Subcomponent //子组件...,轮胎图纸 public interface WheelGraph { Wheel makeWheel(); //造轮胎 @Subcomponent.Factory //告知CarGraph...create(); //造轮胎 Wheel wheel = wheelGraph.makeWheel(); 然后我们看下子组件是如何使用父组件的能力的,在WheelGraph里添加一个inject, @Subcomponent...表示我想要一个Activity级别的作用域 } 使用, @ActivityScope //使用自定义注解 public class Wheel { } @ActivityScope //使用自定义注解 @Subcomponent

69310
领券