blob: e0de05271d1784afed6b46a36c269c24cc38ef20 [file] [log] [blame]
crazyboblee66b415a2006-08-25 02:01:19 +00001/**
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
17package com.google.inject;
18
crazyboblee62fcdde2007-02-03 02:10:13 +000019import java.util.List;
kevinb9na99dca72007-02-11 04:48:57 +000020import java.util.Map;
crazyboblee4602a6f2007-02-15 02:45:18 +000021import java.lang.annotation.Annotation;
crazybobleea6e73982007-02-02 00:21:07 +000022
crazyboblee66b415a2006-08-25 02:01:19 +000023/**
24 * Injects dependencies into constructors, methods and fields annotated with
crazyboblee4602a6f2007-02-15 02:45:18 +000025 * {@code @}{@link Inject}. Provides access to {@link Binding}s.
crazyboblee66b415a2006-08-25 02:01:19 +000026 *
crazyboblee278ee4d2007-02-15 19:23:13 +000027 * <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 *
crazyboblee66b415a2006-08-25 02:01:19 +000032 * @author crazybob@google.com (Bob Lee)
kevinb9na99dca72007-02-11 04:48:57 +000033 * @see ContainerBuilder
crazyboblee66b415a2006-08-25 02:01:19 +000034 */
35public interface Container {
36
37 /**
crazyboblee66b415a2006-08-25 02:01:19 +000038 * Injects dependencies into the fields and methods of an existing object.
39 */
crazyboblee63b592b2007-01-25 02:45:24 +000040 void injectMembers(Object o);
crazyboblee66b415a2006-08-25 02:01:19 +000041
42 /**
crazyboblee63b592b2007-01-25 02:45:24 +000043 * Gets the factory bound to the given key.
crazyboblee66b415a2006-08-25 02:01:19 +000044 */
crazyboblee63b592b2007-01-25 02:45:24 +000045 <T> Factory<T> getFactory(Key<T> key);
crazyboblee07e41822006-11-21 01:27:08 +000046
47 /**
crazybobleea6e73982007-02-02 00:21:07 +000048 * Gets all bindings.
crazyboblee07e41822006-11-21 01:27:08 +000049 */
crazybobleea6e73982007-02-02 00:21:07 +000050 Map<Key<?>, Binding<?>> getBindings();
51
52 /**
53 * Gets a binding for the given key.
54 */
55 <T> Binding<T> getBinding(Key<T> key);
crazyboblee62fcdde2007-02-03 02:10:13 +000056
57 /**
58 * Finds all bindings to the given type.
59 */
60 <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type);
crazybobleea3b0c052007-02-03 08:53:46 +000061
62 /**
crazyboblee1814fa42007-02-03 09:28:36 +000063 * Gets the factory bound to the given type.
crazybobleea3b0c052007-02-03 08:53:46 +000064 */
65 <T> Factory<T> getFactory(Class<T> type);
66
67 /**
crazyboblee1814fa42007-02-03 09:28:36 +000068 * Gets the factory bound to the given type.
crazybobleea3b0c052007-02-03 08:53:46 +000069 */
70 <T> Factory<T> getFactory(TypeLiteral<T> type);
crazyboblee1814fa42007-02-03 09:28:36 +000071
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);
crazybobleee5fbbb02007-02-05 07:00:27 +000086
87 /**
crazyboblee4602a6f2007-02-15 02:45:18 +000088 * Gets an instance from the factory bound to the given type and annotation.
crazybobleee5fbbb02007-02-05 07:00:27 +000089 */
crazyboblee4602a6f2007-02-15 02:45:18 +000090 <T> T getInstance(TypeLiteral<T> type,
91 Annotation annotation);
crazybobleee5fbbb02007-02-05 07:00:27 +000092
93 /**
crazyboblee4602a6f2007-02-15 02:45:18 +000094 * Gets an instance from the factory bound to the given type and annotation.
crazybobleee5fbbb02007-02-05 07:00:27 +000095 */
crazyboblee4602a6f2007-02-15 02:45:18 +000096 <T> T getInstance(Class<T> type,
97 Annotation annotation);
crazybobleee5fbbb02007-02-05 07:00:27 +000098
99 /**
crazyboblee4602a6f2007-02-15 02:45:18 +0000100 * Gets the factory bound to the given type and annotation.
crazybobleee5fbbb02007-02-05 07:00:27 +0000101 */
crazyboblee4602a6f2007-02-15 02:45:18 +0000102 <T> Factory<T> getFactory(Class<T> type,
103 Annotation annotation);
crazybobleee5fbbb02007-02-05 07:00:27 +0000104
105 /**
crazyboblee4602a6f2007-02-15 02:45:18 +0000106 * Gets the factory bound to the given type and annotation.
crazybobleee5fbbb02007-02-05 07:00:27 +0000107 */
crazyboblee4602a6f2007-02-15 02:45:18 +0000108 <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);
crazyboblee66b415a2006-08-25 02:01:19 +0000134}