栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Multibinding概括guice的机械手示例

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Multibinding概括guice的机械手示例

看起来您将需要跳过一些箍,以保证私有模块的绑定状态,以便它们可以在顶级注射器的多重绑定中使用。

这应该工作:

public class SquareModule extends AbstractModule { // does not extend PrivateModule  @Overide public void configure() {    // this key is unique; each module needs its own!    final Key<MyInterface> keyToExpose        = Key.get(MyInterface.class, Names.named("square"));    install(new PrivateModule() {      @Override public void configure() {        // Your private bindings go here, including the binding for MyInterface.        // You can install other modules here as well!        ...        // expose the MyInterface binding with the unique key        bind(keyToExpose).to(MyInterface.class);        expose(keyToExpose);      }    });    // add the exposed unique key to the multibinding    Multibinder.newSetBinder(binder(), MyInterface.class).addBinding().to(keyToExpose);  }}

此解决方法是必需的,因为需要在顶级进样器处进行多重绑定。但是专用模块绑定对该注入器不可见,因此您需要公开它们。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570055.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号