com.google.inject
Interface Scope


public interface Scope

A scope which bound objects can reside in. Mapping scopes by name with ContainerBuilder.scope(java.lang.String, com.google.inject.Scope) can help avoid compile time dependencies on the Scope implementation (if desired) and enable the use of the Scoped annotation.

Scope implementations should override #toString in the returned factory and include the creator's {#toString} output. Doing so aids debugging. They should also override their own #toString method.

Author:
crazybob@google.com (Bob Lee)

Method Summary
<T> Factory<T>
scope(Key<T> key, Factory<T> creator)
          Scopes a factory.
 

Method Detail

scope

<T> Factory<T> scope(Key<T> key,
                     Factory<T> creator)
Scopes a factory. The returned factory returns objects from this scope. If an object does not exist in this scope, the factory can use the given creator to create one.

Parameters:
key - binding key
creator - creates new instances as needed
Returns:
a new factory which only delegates to the given factory when an instance of the requested object doesn't already exist in the scope