鍍金池/ 教程/ Android/ Untargetted Bindings
Just-in-time Bindings
Binding Annotations
Standard Injection
第一個(gè)例子 Hello World
Bindings 概述
Linked Bindings
如何綁定 generic 類型
@Provides Methods
RoboGuice 功能描述
概述
綜合示例 Astroboy
Inject Resources
Instance Bindings
Inject 自定義 View
Scopes
Provider Bindings
Untargetted Bindings
Inject Extra
第一個(gè)例子 Hello World
Inject Context
發(fā)送接收 Events
Inject View

Untargetted Bindings

在創(chuàng)建 Bindings 時(shí),也可以不給出綁定的目標(biāo),通常用于含有 @ImplementedBy 和 @ProvidedBy (后面介紹)的實(shí)類 (Concrete classes 或 type)。 Untargeted bindings 目的是通知 Injector 某個(gè)類類型,從而 Injector 可以預(yù)先準(zhǔn)備某個(gè)依賴。Untargetted Bindings 不含 to 語句。

例如:

bind(MyConcreteClass.class);
bind(AnotherConcreteClass.class).in(Singleton.class);

但如果此時(shí)需要同時(shí)使用 binding annotations 時(shí),需要為綁定添加目標(biāo),即使是綁定到同一個(gè)實(shí)類,如:

bind(MyConcreteClass.class)
 .annotatedWith(Names.named("foo"))
 .to(MyConcreteClass.class);
bind(AnotherConcreteClass.class)
 .annotatedWith(Names.named("foo"))
 .to(AnotherConcreteClass.class)
 .in(Singleton.class);
上一篇:Standard Injection下一篇:概述