代码之家  ›  专栏  ›  技术社区  ›  Arnaud Denoyelle

GWT杜松子酒/杜松子酒注入订单

  •  2
  • Arnaud Denoyelle  · 技术社区  · 12 年前

    我有一个GWT应用程序,它使用Gin/Guice。

    我的需要 :在注入所有字段之后调用一个方法。

    以下是Javadoc关于 @Inject

    Constructors are injected first, followed by fields, and then methods.
    

    所以我的想法是只有一个方法用 @Inject 并将其用作注射后的方法。以下是我的代码摘录:

    //An injected attribute (a JSR 303 validator)
    @Inject
    private Validator validator;
    
    //A constructor with some injectable args.
    @Inject
    public MyClass(...){
    }
    
    //And my post-injection method
    @Inject
    private void postInjection(){
      Log.warn("Validator null? "+(validator==null));
    }
    

    问题 :日志显示 true (=验证器为null,就好像它还没有被注入一样)。稍后,在单击按钮时调用验证器,它看起来是非null的。我测试了其他可注射属性,也有同样的问题。

    1) 注射后使用杜松子酒有没有一种常见的模式?

    2) GWT中Gin的注入顺序不同吗?这是个虫子吗?

    1 回复  |  直到 12 年前
        1
  •  2
  •   Thomas Broyer    12 年前

    GIN在2.0之前有一个错误,在2.1中已经修复。

    https://code.google.com/p/google-gin/issues/detail?id=183