【发布时间】:2015-02-05 21:57:42
【问题描述】:
使用 GWTP/Gin,是否可以在编译期间选择性地安装模块?我们有一个案例,我们希望在“开发”模式下运行时只有在应用程序中可用的演示者和视图,其中该模式由 .gwt.xml 文件中的标志确定(由构建设置)。
以前,我们使用 MVC 架构运行 GXT,并且会在我们的模块中执行以下操作:
<replace-with class="com.mypackage.DevEditController" >
<all>
<when-property-is name="isDevelopment" value="true" />
<when-type-is class="com.mypackage.EditController" />
</all>
</replace-with>
<replace-with class="com.mypackage.StubEditController" >
<all>
<when-property-is name="isDevelopment" value="false" />
<when-type-is class="com.mypackage.EditController" />
</all>
</replace-with>
并会使用以下内容创建控制器:
(EditController)GWT.create(EditController.class);
我想用 GWTP 做一些类似的事情,应用程序的非开发编译不会知道关于这个演示者的任何事情。本质上,在我们的模块文件中做一些类似的事情:
<set-configuration-property name="gin.ginjector.modules"
value="com.mypackage.gin.SharedModule"/>
if this is development mode:
<set-configuration-property name="gin.ginjector.module.desktop"
value="com.mypackage.gin.DevDesktopModule"/>
else:
<set-configuration-property name="gin.ginjector.module.desktop"
value="com.mypackage.gin.DesktopModule"/>
DesktopModule 和 DevModule 会做同样的事情,但 DevDesktopModule 会加载一个包含演示者/视图绑定的附加模块 (TestModule)。
从配置的角度来看这是可行的吗?我以为我可以通过构建过程切换出两个 .gwt.xml 文件来做到这一点,但是构建过程总是看到 TestModule 文件,无论它是否正在安装(显然是因为注入)。这是当模块存在于源代码树中但从未安装时我们收到的错误消息(这是来自我们不希望安装它的构建)
[ERROR] Error injecting com.blah.test.TestPresenter$MyView: Unable to create or inherit binding: No @Inject or default constructor found for com.blah.test.TestPresenter$MyView
Path to required node:
com.google.gwt.inject.client.AsyncProvider<com.blah.test.TestPresenter> [com.gwtplatform.mvp.client.ClientGinjector#getcomblahtestTestPresenter()]
-> com.blah.test.TestPresenter [Implicit injection of com.google.gwt.inject.client.AsyncProvider<com.blah.test.TestPresenter>]
-> com.blah.test.TestPresenter$MyView [@Inject constructor of com.blah.test.TestPresenter]
[ERROR] Errors in 'gen/com/gwtplatform/mvp/client/DesktopGinjectorProvider.java'
[ERROR] Line 8: Failed to resolve 'com.gwtplatform.mvp.client.DesktopGinjector' via deferred binding
[WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)
[WARN] com.gwtplatform.mvp.client.com_gwtplatform_mvp_client_DesktopGinjectorImpl
感谢您对该问题的任何见解,或在我们的应用程序中包含“有条件包含”模块的替代解决方案。
【问题讨论】:
标签: gwtp gwt-platform gwt-gin