简体   繁体   English

我应该在哪里放胶水?

[英]Where I should put glue?

I have application written with Java and Guice. 我有用Java和Guice编写的应用程序。 For this application I have several views. 对于此应用程序,我有几种看法。 Some of them use Guice, other - doesn't. 他们中的一些人使用Guice,其他人则不使用。 Now I want to separate my code into independent modules. 现在,我想将代码分成独立的模块。 I can devide application logic, viewers interfaces and viewers implementations. 我可以设计应用程序逻辑,查看器界面和查看器实现。 In which module should I put Guice configuration per each view variant? 每个视图变体应在哪个模块中放置Guice配置? I think there is two possible answers - into viewers module (in this case all viewers will depend from Guice) or contribute such ModuleConfiguration separately from module. 我认为有两个可能的答案-进入查看器模块(在这种情况下,所有查看器都将依赖Guice)或与模块分开提供此类ModuleConfiguration。 What is the right way? 正确的方法是什么? If separably, what is the best way for such contribution? 如果分开,进行这种贡献的最佳方法是什么?

Just split the configuration into several Guice Modules near the code that they are wiring. 只需将配置拆分成几个Guice模块,使其靠近所连接的代码。 Then use composition to construct an injector. 然后使用合成物构造注射器。

Injector injector = Guice.createInjector(new ModuleA(), new ModuleB());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM