通过多模块应用程序中的组件或模块揭示匕首提供的依赖关系?
我正在寻找有关多模块Android应用中匕首最佳代码结构的一些指导。 假设我们有特色杂志和特征emoduleb,这两者都取决于共同的codemodemodule。
ID喜欢Common CodeModule,可以使用匕首提供一些依赖性,并为特征emodulea和featuremoduleb提供。
最好使用来自CommonCodeModeule的组件来暴露这些依赖项,因此两个特征模块都需要在注入时间创建该组件 或者 通过允许两个特征模块使用驻留在CommonCodeModule中的模块来揭示这些依赖性吗?
I am looking for some guidance on the best code structure for dagger in multi module android apps.
Lets say we have featureModuleA and featureModuleB, both of which depend on commonCodeModule.
Id like commonCodeModule to provide some dependencies using dagger, to both featureModuleA and featureModuleB.
Would it be better to expose those dependencies using a Component from commonCodeModule, therefore both feature modules need to create that component at injection time
OR
is it better to expose those dependencies by allowing both feature modules to use the Module residing in commonCodeModule?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
他们是否需要从CommonModule的图表共享实例?如果是,那么使用组件依赖性将更加干净。组件方法不仅要揭露现成的模块,还要凌乱,但是您可以更多地控制组件中对象的生命周期。
此外,如果您来自CommonModule的依赖项较小,则可以在featureModule组件中使用
@bindsinstance
播种它们。绑定实例将剥夺您的特征模块成分的知识,这些知识来自CommonModule的任何类型的组件。我的两分钱揭露模块:如果featuremodulea和taperulemoduleb可以在commonmodules中创建自己的类实例,那么您可以揭示模块。
Do they need to share the instances from the graph of the commonModule? If yes, then it would be cleaner to use component dependency. Component approach is a bit messier than just exposing ready-made modules, but you more control over lifecycle of objects in the component.
In addition, if you have smaller set of dependencies coming from commonModule you can seed them using
@BindsInstance
in your featureModule components. Binding instances will deprive your feature module components of knowledge about any kind of component coming from the commonModule.My two cents on exposing modules: If featureModuleA and featureModuleB can create their own instances of the classes in the commonModules, then you can expose Modules.