简体   繁体   English

Guice的bind()中的in()...是做什么的?

[英]in() in Guice's bind()… what does it do?

In Guice's documentation, the chapter about Untargetted Bindings presents this example: 在Guice的文档中,有关无目标绑定的章节介绍了以下示例:

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

What does the in() do? in()做什么的? The doc doesn't mention what it is for. 该文档没有提及其用途。

It's just the scope I think. 这只是我认为的范围。 It also accept the Scopes enum - either Singleton or NO_SCOPE. 它还接受Scopes枚举-Singleton或NO_SCOPE。

A scope is a level of visibility that instances provided by Guice may have. 范围是Guice提供的实例可能具有的可见性级别。 By default, an instance created by the Injector has no scope, meaning it has no state from the framework's perspective -- the Injector creates it, injects it once into the class that required it, and then immediately forgets it. 默认情况下,由Injector创建的实例没有作用域,这意味着从框架的角度来看它没有任何状态-Injector创建它,将其注入到需要它的类中,然后立即将其忘记。 Associating a scope with a particular binding allows the created instance to be "remembered" and possibly used again for other injections. 将范围与特定绑定相关联可以使创建的实例“被记住”,并可能再次用于其他注入。

http://google-guice.googlecode.com/svn/tags/3.0/javadoc/com/google/inject/Scopes.html#SINGLETON http://google-guice.googlecode.com/svn/tags/3.0/javadoc/com/google/inject/Scopes.html#SINGLETON

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM