KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > inject > Injector


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
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 /**
23  * Fulfills requests for the object instances that make up your application,
24  * always ensuring that these instances are properly injected before they are
25  * returned. The {@code Injector} is the heart of the Guice framework,
26  * although you don't typically interact with it directly very often. This
27  * "behind-the-scenes" operation is what distinguishes the dependency
28  * injection pattern from its cousin, service locator.
29  *
30  * <p>The {@code Injector} API has a few additional features: it allows
31  * pre-constructed instances to have their fields and methods injected and
32  * offers programmatic introspection to support tool development.
33  *
34  * <p>Contains several default bindings:
35  *
36  * <ul>
37  * <li>This {@link Injector} instance itself
38  * <li>A {@code Provider<T>} for each binding of type {@code T}
39  * <li>The {@link java.util.logging.Logger} for the class being injected
40  * <li>The {@link Stage} in which the Injector was created
41  * </ul>
42  *
43  * Injectors are created using the facade class {@link Guice}.
44  *
45  * @author crazybob@google.com (Bob Lee)
46  */

47 public interface Injector {
48
49   /**
50    * Injects dependencies into the fields and methods of an existing object.
51    * Does not inject the constructor.
52    */

53   void injectMembers(Object JavaDoc o);
54
55   /**
56    * Gets all explicit bindings.
57    */

58   Map JavaDoc<Key<?>, Binding<?>> getBindings();
59
60   /**
61    * Gets a binding for the given key.
62    */

63   <T> Binding<T> getBinding(Key<T> key);
64
65   /**
66    * Finds all bindings to the given type.
67    */

68   <T> List JavaDoc<Binding<T>> findBindingsByType(TypeLiteral<T> type);
69
70   /**
71    * Gets the provider bound to the given key.
72    */

73   <T> Provider<T> getProvider(Key<T> key);
74
75   /**
76    * Gets the provider bound to the given type.
77    */

78   <T> Provider<T> getProvider(Class JavaDoc<T> type);
79
80   /**
81    * Gets an instance bound to the given key; equivalent to
82    * {@code getProvider(key).get()}.
83    */

84   <T> T getInstance(Key<T> key);
85
86   /**
87    * Gets an instance bound to the given type; equivalent to
88    * {@code getProvider(type).get()}.
89    */

90   <T> T getInstance(Class JavaDoc<T> type);
91 }
92
Popular Tags