Android(安卓)RoboGuice 使用指南(9):Untargetted Bindings
16lz
2021-01-26
在创建Bindings时,也可以不给出绑定的目标,通常用于含有@ImplementedBy 和@ProvidedBy (后面介绍)的实类(Concrete classes 或type)。 Untargeted bindings 目的是通知Injector 某个类类型,从而Injector可以预先准备某个依赖。Untargetted Bindings不含to语句。
例如:
bind(MyConcreteClass.class);bind(AnotherConcreteClass.class).in(Singleton.class);
但如果此时需要同时使用binding annotations 时,需要为绑定添加目标,即使是绑定到同一个实类,如:
bind(MyConcreteClass.class) .annotatedWith(Names.named("foo")) .to(MyConcreteClass.class);bind(AnotherConcreteClass.class) .annotatedWith(Names.named("foo")) .to(AnotherConcreteClass.class) .in(Singleton.class);
更多相关文章
- Android(安卓)开发笔记第二季 DialogFragment
- android 数组数据绑定到listview
- Android数组显示
- Android:UI更新方法二:View.postInvalidate+Thread+Runnable
- Android(安卓)封装的数据库管理操作类
- Android(安卓)ContentResolver 使用例子,读取联系人
- Android(安卓)TextView 一些字体颜色、大小设置属性
- android使用篇(四) 注解依赖注入IOC实现绑定控件
- SQLite轻量级数据库的注意事项