crazyboblee | 66b415a | 2006-08-25 02:01:19 +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 | */ |
| 16 | |
| 17 | package com.google.inject; |
| 18 | |
crazyboblee | 62fcdde | 2007-02-03 02:10:13 +0000 | [diff] [blame] | 19 | import java.util.List; |
kevinb9n | a99dca7 | 2007-02-11 04:48:57 +0000 | [diff] [blame] | 20 | import java.util.Map; |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 21 | import java.lang.annotation.Annotation; |
crazyboblee | a6e7398 | 2007-02-02 00:21:07 +0000 | [diff] [blame] | 22 | |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 23 | /** |
| 24 | * Injects dependencies into constructors, methods and fields annotated with |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 25 | * {@code @}{@link Inject}. Provides access to {@link Binding}s. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 26 | * |
crazyboblee | 278ee4d | 2007-02-15 19:23:13 +0000 | [diff] [blame^] | 27 | * <p>Automatically converts constants as needed from {@code String} to any |
| 28 | * primitive type as well as {@code enum} and {@code Class<?>}. Automatically |
| 29 | * boxes and unboxes primitives. For example, in the absence of a binding to |
| 30 | * {@code int}, the container will look for a binding to {@code Integer}. |
| 31 | * |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 32 | * @author crazybob@google.com (Bob Lee) |
kevinb9n | a99dca7 | 2007-02-11 04:48:57 +0000 | [diff] [blame] | 33 | * @see ContainerBuilder |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 34 | */ |
| 35 | public interface Container { |
| 36 | |
| 37 | /** |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 38 | * Injects dependencies into the fields and methods of an existing object. |
| 39 | */ |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 40 | void injectMembers(Object o); |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 41 | |
| 42 | /** |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 43 | * Gets the factory bound to the given key. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 44 | */ |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 45 | <T> Factory<T> getFactory(Key<T> key); |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 46 | |
| 47 | /** |
crazyboblee | a6e7398 | 2007-02-02 00:21:07 +0000 | [diff] [blame] | 48 | * Gets all bindings. |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 49 | */ |
crazyboblee | a6e7398 | 2007-02-02 00:21:07 +0000 | [diff] [blame] | 50 | Map<Key<?>, Binding<?>> getBindings(); |
| 51 | |
| 52 | /** |
| 53 | * Gets a binding for the given key. |
| 54 | */ |
| 55 | <T> Binding<T> getBinding(Key<T> key); |
crazyboblee | 62fcdde | 2007-02-03 02:10:13 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Finds all bindings to the given type. |
| 59 | */ |
| 60 | <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type); |
crazyboblee | a3b0c05 | 2007-02-03 08:53:46 +0000 | [diff] [blame] | 61 | |
| 62 | /** |
crazyboblee | 1814fa4 | 2007-02-03 09:28:36 +0000 | [diff] [blame] | 63 | * Gets the factory bound to the given type. |
crazyboblee | a3b0c05 | 2007-02-03 08:53:46 +0000 | [diff] [blame] | 64 | */ |
| 65 | <T> Factory<T> getFactory(Class<T> type); |
| 66 | |
| 67 | /** |
crazyboblee | 1814fa4 | 2007-02-03 09:28:36 +0000 | [diff] [blame] | 68 | * Gets the factory bound to the given type. |
crazyboblee | a3b0c05 | 2007-02-03 08:53:46 +0000 | [diff] [blame] | 69 | */ |
| 70 | <T> Factory<T> getFactory(TypeLiteral<T> type); |
crazyboblee | 1814fa4 | 2007-02-03 09:28:36 +0000 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Gets an instance from the factory bound to the given type. |
| 74 | */ |
| 75 | <T> T getInstance(TypeLiteral<T> type); |
| 76 | |
| 77 | /** |
| 78 | * Gets an instance from the factory bound to the given type. |
| 79 | */ |
| 80 | <T> T getInstance(Class<T> type); |
| 81 | |
| 82 | /** |
| 83 | * Gets an instance from the factory bound to the given key. |
| 84 | */ |
| 85 | <T> T getInstance(Key<T> key); |
crazyboblee | e5fbbb0 | 2007-02-05 07:00:27 +0000 | [diff] [blame] | 86 | |
| 87 | /** |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 88 | * Gets an instance from the factory bound to the given type and annotation. |
crazyboblee | e5fbbb0 | 2007-02-05 07:00:27 +0000 | [diff] [blame] | 89 | */ |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 90 | <T> T getInstance(TypeLiteral<T> type, |
| 91 | Annotation annotation); |
crazyboblee | e5fbbb0 | 2007-02-05 07:00:27 +0000 | [diff] [blame] | 92 | |
| 93 | /** |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 94 | * Gets an instance from the factory bound to the given type and annotation. |
crazyboblee | e5fbbb0 | 2007-02-05 07:00:27 +0000 | [diff] [blame] | 95 | */ |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 96 | <T> T getInstance(Class<T> type, |
| 97 | Annotation annotation); |
crazyboblee | e5fbbb0 | 2007-02-05 07:00:27 +0000 | [diff] [blame] | 98 | |
| 99 | /** |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 100 | * Gets the factory bound to the given type and annotation. |
crazyboblee | e5fbbb0 | 2007-02-05 07:00:27 +0000 | [diff] [blame] | 101 | */ |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 102 | <T> Factory<T> getFactory(Class<T> type, |
| 103 | Annotation annotation); |
crazyboblee | e5fbbb0 | 2007-02-05 07:00:27 +0000 | [diff] [blame] | 104 | |
| 105 | /** |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 106 | * Gets the factory bound to the given type and annotation. |
crazyboblee | e5fbbb0 | 2007-02-05 07:00:27 +0000 | [diff] [blame] | 107 | */ |
crazyboblee | 4602a6f | 2007-02-15 02:45:18 +0000 | [diff] [blame] | 108 | <T> Factory<T> getFactory(TypeLiteral<T> type, |
| 109 | Annotation annotation); |
| 110 | |
| 111 | /** |
| 112 | * Gets an instance from the factory bound to the given type and annotation. |
| 113 | */ |
| 114 | <T> T getInstance(TypeLiteral<T> type, |
| 115 | Class<? extends Annotation> annotationType); |
| 116 | |
| 117 | /** |
| 118 | * Gets an instance from the factory bound to the given type and annotation. |
| 119 | */ |
| 120 | <T> T getInstance(Class<T> type, |
| 121 | Class<? extends Annotation> annotationType); |
| 122 | |
| 123 | /** |
| 124 | * Gets the factory bound to the given type and annotation. |
| 125 | */ |
| 126 | <T> Factory<T> getFactory(Class<T> type, |
| 127 | Class<? extends Annotation> annotationType); |
| 128 | |
| 129 | /** |
| 130 | * Gets the factory bound to the given type and annotation. |
| 131 | */ |
| 132 | <T> Factory<T> getFactory(TypeLiteral<T> type, |
| 133 | Class<? extends Annotation> annotationType); |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 134 | } |