Mic*_*UER 1 gwt binding annotations
我希望你们的编码都很好。所以...我正在重构正在使用的GWT应用程序的客户端,我想知道一些事情。日复一日地寻找答案,我决定问您您的观点...
标题是相当理解的,但是有我想做的一小段。
我想改变这样的东西
public AnnotatedObject annotated = GWT.create(AnnotatedObject.class);
Run Code Online (Sandbox Code Playgroud)
通过这样的事情
@CreativeAnnotation
public AnnotatedObject;
Run Code Online (Sandbox Code Playgroud)
我不得不说,在我的xxx.gwt.xml中,我做了这样的事情:
<replace-with class="package.AnnotationObject2">
<when-type-is class="package.AnnotationObject" />
</replace-with>
Run Code Online (Sandbox Code Playgroud)
如您所见,我的递减替换类是AnnotationObject2,目前,我在上面的替换类之间添加了一行,并且有:
<replace-with class="package.AnnotationObject1">
<when-type-is class="package.AnnotationObject" />
<when-property-is name="type" value="object1" />
</replace-with>
<replace-with class="package.AnnotationObject2">
<when-type-is class="package.AnnotationObject" />
<when-property-is name="type" value="object2" />
</replace-with>
Run Code Online (Sandbox Code Playgroud)
我不太喜欢使用xxx.html的元数据,因此我想要的结果是:
@CreativeAnnotation(type = "object2")
public AnnotatedObject;
Run Code Online (Sandbox Code Playgroud)
那么,您是否认为GWT可以实现这种事情(我不得不说我使用GWT 2.5,这是由于客户的需求引起的)吗?如果可以,您能帮我吗?
提前致谢。
编辑:我的意思是,我知道GIN ...只是想知道如何从头开始。
您可以通过在GIN中使用依赖项注入来实现。GIN自动使用GWT.create()创建必须注入的对象。例如:
class MyView {
interface MyUiBinder extends UiBinder<Widget, MyView> {
}
@Inject
MyView(MyUiBinder uiBinder) {
initWidget(uiBinder.createAndBindUi(this));
}
}
Run Code Online (Sandbox Code Playgroud)
使用依赖项注入,您还可以指定要在GIN模块中实例化接口的哪种实现:
public class MyModule extends AbstractGinModule {
protected void configure() {
bind(AnnotationObject.class).annotatedWith(Names.named("object1").to(AnnotationObject1.class);
bind(AnnotationObject.class).annotatedWith(Names.named("object2").to(AnnotationObject2.class);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在您的代码中:
public class MyClass {
@Inject
public MyClass(@Named("object1") AnnotationObject annotationObject) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
您也可以使用自定义绑定注释而不是“命名”注释。
| 归档时间: |
|
| 查看次数: |
401 次 |
| 最近记录: |