blob: c9121899203bd9d071db9c9495120efcc45002b1 [file] [log] [blame]
crazyboblee63b592b2007-01-25 02:45:24 +00001// Copyright 2006 Google Inc. All Rights Reserved.
crazyboblee66b415a2006-08-25 02:01:19 +00002
3package com.google.inject;
4
crazyboblee66b415a2006-08-25 02:01:19 +00005/**
crazyboblee63b592b2007-01-25 02:45:24 +00006 * A scope which bound objects can reside in. Add a new scope using {@link
7 * com.google.inject.ContainerBuilder#put(String, Scope)} and reference it from
8 * bindings using its name.
crazyboblee66b415a2006-08-25 02:01:19 +00009 *
crazyboblee63b592b2007-01-25 02:45:24 +000010 * @author crazybob@google.com (Bob Lee)
crazyboblee66b415a2006-08-25 02:01:19 +000011 */
crazyboblee63b592b2007-01-25 02:45:24 +000012public interface Scope {
crazyboblee66b415a2006-08-25 02:01:19 +000013
14 /**
crazyboblee63b592b2007-01-25 02:45:24 +000015 * Scopes a factory. The returned factory returns objects from this scope.
16 * If an object does not exist in this scope, the factory can use the given
17 * creator to create one.
crazyboblee66b415a2006-08-25 02:01:19 +000018 *
crazyboblee63b592b2007-01-25 02:45:24 +000019 * @param key binding key
20 * @param creator creates new instances as needed
21 * @return a new factory which only delegates to the given factory when an
22 * instance of the requested object doesn't already exist in the scope
crazyboblee66b415a2006-08-25 02:01:19 +000023 */
crazyboblee63b592b2007-01-25 02:45:24 +000024 public <T> Factory<T> scope(Key<T> key, Factory<T> creator);
crazyboblee66b415a2006-08-25 02:01:19 +000025}