Untargeted Bindings
绑定没有实现类的bean
,即有bind()
没有to()
的bean
。
This is most useful for concrete classes and types annotated by either @ImplementedBy or @ProvidedBy. An untargetted binding informs the injector about a type, so it may prepare dependencies eagerly. Untargetted bindings have no to clause, like so:
因为没有具体的实现类,所以injector
会采用饿汉模式,去找到容器中对应的父类bean
或子类bean
,赶紧set
给这个binding
,这对容器中被@ImplementedBy
或@ProvidedBy
注解过的父类并且还有具体的实现类的情况很有用:
bind(MyConcreteClass.class);
bind(AnotherConcreteClass.class).in(Singleton.class);