【问题标题】:Optional module installation可选模块安装
【发布时间】: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


    【解决方案1】:

    我不使用 GWTP,而只是使用 Activity/Place 架构。 我发现以下解决方案适合我的情况。

    *.gwt.xml* 中的配置参数由构建脚本设置,稍后在 EntryPoint 中解析。

    <define-configuration-property name="demoMode" is-multi-valued="true" />
    <extend-configuration-property name="demoMode" value="false" />
    

    基于此参数的视图/演示者配置,并在 GIN 模块中初始化正确的视图。

    @Provides @Singleton
    public LoginView getLoginView() {
      if (SharedState.IS_DEMO_MODE) {
        return new LoginViewMobileDemo();
      } else {
        return new LoginViewMobile();
      }
    }
    

    【讨论】:

      【解决方案2】:

      万一其他人遇到类似情况...我最终将可选模块代码移动到独立 GWT 模块中,将其从主应用程序源代码树中删除。然后可以选择在我们的应用程序 .gwt.xml 文件中继承该模块(通过构建过程)。

      即使在设置之后,我仍然收到有关无法创建或继承绑定的 Gin 警告。我在应用程序 .gwt.xml 文件中按照指定顺序将其追踪到了一个问题。在设置“gin.ginjector.modules”之前我正在继承;一旦我更改了订单,一切都按预期进行。

      <set-configuration-property name="gin.ginjector.modules" value="com.test.app.SharedModule"/>
      
      <inherits name="com.test.optional.OptionalModule" />
      

      【讨论】:

        猜你喜欢
        • 2022-07-12
        • 1970-01-01
        • 1970-01-01
        • 2012-06-27
        • 2017-09-13
        • 1970-01-01
        • 2013-08-23
        • 1970-01-01
        • 2016-07-11
        相关资源
        最近更新 更多