crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 1 | // Copyright 2006 Google Inc. All Rights Reserved. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 2 | |
| 3 | package com.google.inject; |
| 4 | |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 5 | /** |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 6 | * 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. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 9 | * |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 10 | * @author crazybob@google.com (Bob Lee) |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 11 | */ |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 12 | public interface Scope { |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 13 | |
| 14 | /** |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 15 | * 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. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 18 | * |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 19 | * @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 |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 23 | */ |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 24 | public <T> Factory<T> scope(Key<T> key, Factory<T> creator); |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 25 | } |