crazyboblee | abc4dd0 | 2007-02-01 01:44:36 +0000 | [diff] [blame] | 1 | /** |
| 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 | */ |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 16 | |
| 17 | package com.google.inject; |
| 18 | |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 19 | /** |
crazyboblee | 5746d5d | 2007-02-18 21:52:24 +0000 | [diff] [blame^] | 20 | * A scope which bound objects can reside in. Scopes a given {@link Locator}. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 21 | * |
crazyboblee | 91c37e3 | 2007-02-15 05:18:57 +0000 | [diff] [blame] | 22 | * <p>Scope implementations should override {@code toString()} in the returned |
crazyboblee | 5746d5d | 2007-02-18 21:52:24 +0000 | [diff] [blame^] | 23 | * locator and include the unscoped locator's {@code toString()} output. Doing |
| 24 | * so aids debugging. They should also override their own {@code toString()} |
crazyboblee | f33d23e | 2007-02-12 04:17:48 +0000 | [diff] [blame] | 25 | * method. |
crazyboblee | a6e7398 | 2007-02-02 00:21:07 +0000 | [diff] [blame] | 26 | * |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 27 | * @author crazybob@google.com (Bob Lee) |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 28 | */ |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 29 | public interface Scope { |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 30 | |
| 31 | /** |
crazyboblee | 5746d5d | 2007-02-18 21:52:24 +0000 | [diff] [blame^] | 32 | * 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. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 35 | * |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 36 | * @param key binding key |
crazyboblee | 5746d5d | 2007-02-18 21:52:24 +0000 | [diff] [blame^] | 37 | * @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 |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 42 | */ |
crazyboblee | 5746d5d | 2007-02-18 21:52:24 +0000 | [diff] [blame^] | 43 | public <T> Locator<T> scope(Key<T> key, Locator<T> unscoped); |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 44 | } |