blob: 37a7130748517ca07388d84060a1a064d9deabab [file] [log] [blame]
crazybobleeabc4dd02007-02-01 01:44:36 +00001/**
2 * Copyright (C) 2006 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
crazyboblee66b415a2006-08-25 02:01:19 +000016
17package com.google.inject;
18
crazyboblee66b415a2006-08-25 02:01:19 +000019/**
crazyboblee5746d5d2007-02-18 21:52:24 +000020 * A scope which bound objects can reside in. Scopes a given {@link Locator}.
crazyboblee66b415a2006-08-25 02:01:19 +000021 *
crazyboblee91c37e32007-02-15 05:18:57 +000022 * <p>Scope implementations should override {@code toString()} in the returned
crazyboblee5746d5d2007-02-18 21:52:24 +000023 * locator and include the unscoped locator's {@code toString()} output. Doing
24 * so aids debugging. They should also override their own {@code toString()}
crazybobleef33d23e2007-02-12 04:17:48 +000025 * method.
crazybobleea6e73982007-02-02 00:21:07 +000026 *
crazyboblee63b592b2007-01-25 02:45:24 +000027 * @author crazybob@google.com (Bob Lee)
crazyboblee66b415a2006-08-25 02:01:19 +000028 */
crazyboblee63b592b2007-01-25 02:45:24 +000029public interface Scope {
crazyboblee66b415a2006-08-25 02:01:19 +000030
31 /**
crazyboblee5746d5d2007-02-18 21:52:24 +000032 * Scopes a locator. The returned locator returns objects from this scope. If
33 * an object does not exist in this scope, the locator can use the given
34 * unscoped locator to retrieve one.
crazyboblee66b415a2006-08-25 02:01:19 +000035 *
crazyboblee63b592b2007-01-25 02:45:24 +000036 * @param key binding key
crazyboblee5746d5d2007-02-18 21:52:24 +000037 * @param unscoped locates an instance when one doesn't already exist in this
38 * scope.
39 * @return a new locator which only delegates to the given unscoped locator
40 * when an instance of the requested object doesn't already exist in this
41 * scope
crazyboblee66b415a2006-08-25 02:01:19 +000042 */
crazyboblee5746d5d2007-02-18 21:52:24 +000043 public <T> Locator<T> scope(Key<T> key, Locator<T> unscoped);
crazyboblee66b415a2006-08-25 02:01:19 +000044}