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);
Copyright © qgao 2021-* all right reserved,powered by Gitbook该文件修订时间: 2022-05-30 15:41:15

results matching ""

    No results matching ""