01: /**
02: * Copyright (C) 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package com.google.inject;
16:
17: import java.util.List;
18: import java.util.Map;
19:
20: /**
21: * Fulfills requests for the object instances that make up your application,
22: * always ensuring that these instances are properly injected before they are
23: * returned. The {@code Injector} is the heart of the Guice framework,
24: * although you don't typically interact with it directly very often. This
25: * "behind-the-scenes" operation is what distinguishes the dependency
26: * injection pattern from its cousin, service locator.
27: *
28: * <p>The {@code Injector} API has a few additional features: it allows
29: * pre-constructed instances to have their fields and methods injected and
30: * offers programmatic introspection to support tool development.
31: *
32: * <p>Contains several default bindings:
33: *
34: * <ul>
35: * <li>This {@link Injector} instance itself
36: * <li>A {@code Provider<T>} for each binding of type {@code T}
37: * <li>The {@link java.util.logging.Logger} for the class being injected
38: * <li>The {@link Stage} in which the Injector was created
39: * </ul>
40: *
41: * Injectors are created using the facade class {@link Guice}.
42: *
43: * @author crazybob@google.com (Bob Lee)
44: */
45: public interface Injector {
46:
47: /**
48: * Injects dependencies into the fields and methods of an existing object.
49: * Does not inject the constructor.
50: */
51: void injectMembers(Object o);
52:
53: /**
54: * Gets all explicit bindings.
55: */
56: Map<Key<?>, Binding<?>> getBindings();
57:
58: /**
59: * Gets a binding for the given key.
60: */
61: <T> Binding<T> getBinding(Key<T> key);
62:
63: /**
64: * Finds all bindings to the given type.
65: */
66: <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type);
67:
68: /**
69: * Gets the provider bound to the given key.
70: */
71: <T> Provider<T> getProvider(Key<T> key);
72:
73: /**
74: * Gets the provider bound to the given type.
75: */
76: <T> Provider<T> getProvider(Class<T> type);
77:
78: /**
79: * Gets an instance bound to the given key; equivalent to
80: * {@code getProvider(key).get()}.
81: */
82: <T> T getInstance(Key<T> key);
83:
84: /**
85: * Gets an instance bound to the given type; equivalent to
86: * {@code getProvider(type).get()}.
87: */
88: <T> T getInstance(Class<T> type);
89: }
|