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 | f33d23e | 2007-02-12 04:17:48 +0000 | [diff] [blame] | 20 | * A scope which bound objects can reside in. Mapping scopes by name with |
| 21 | * {@link ContainerBuilder#scope} can help avoid compile time dependencies |
| 22 | * on the {@code Scope} implementation (if desired) and enable the use of the |
| 23 | * {@link Scoped} annotation. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 24 | * |
crazyboblee | f33d23e | 2007-02-12 04:17:48 +0000 | [diff] [blame] | 25 | * <p>Scope implementations should override {@link #toString} in the returned |
| 26 | * factory and include the creator's {#toString} output. Doing so aids |
| 27 | * debugging. They should also override their own {@link #toString} |
| 28 | * method. |
crazyboblee | a6e7398 | 2007-02-02 00:21:07 +0000 | [diff] [blame] | 29 | * |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 30 | * @author crazybob@google.com (Bob Lee) |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 31 | */ |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 32 | public interface Scope { |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 33 | |
| 34 | /** |
kevinb9n | a99dca7 | 2007-02-11 04:48:57 +0000 | [diff] [blame] | 35 | * Scopes a factory. The returned factory returns objects from this scope. If |
| 36 | * an object does not exist in this scope, the factory can use the given |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 37 | * creator to create one. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 38 | * |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 39 | * @param key binding key |
| 40 | * @param creator creates new instances as needed |
| 41 | * @return a new factory which only delegates to the given factory when an |
kevinb9n | a99dca7 | 2007-02-11 04:48:57 +0000 | [diff] [blame] | 42 | * instance of the requested object doesn't already exist in the scope |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 43 | */ |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 44 | public <T> Factory<T> scope(Key<T> key, Factory<T> creator); |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 45 | } |