blob: a7113ff1013689421feafa4c0e7f1adc514394fc [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 *
crazyboblee66b415a2006-08-25 02:01:19 +000027 * @author crazybob@google.com (Bob Lee)
kevinb9na99dca72007-02-11 04:48:57 +000028 * @see ContainerBuilder
crazyboblee66b415a2006-08-25 02:01:19 +000029 */
30public interface Container {
31
32 /**
crazyboblee66b415a2006-08-25 02:01:19 +000033 * Injects dependencies into the fields and methods of an existing object.
34 */
crazyboblee63b592b2007-01-25 02:45:24 +000035 void injectMembers(Object o);
crazyboblee66b415a2006-08-25 02:01:19 +000036
37 /**
crazyboblee63b592b2007-01-25 02:45:24 +000038 * Gets the factory bound to the given key.
crazyboblee66b415a2006-08-25 02:01:19 +000039 */
crazyboblee63b592b2007-01-25 02:45:24 +000040 <T> Factory<T> getFactory(Key<T> key);
crazyboblee07e41822006-11-21 01:27:08 +000041
42 /**
crazybobleea6e73982007-02-02 00:21:07 +000043 * Gets all bindings.
crazyboblee07e41822006-11-21 01:27:08 +000044 */
crazybobleea6e73982007-02-02 00:21:07 +000045 Map<Key<?>, Binding<?>> getBindings();
46
47 /**
48 * Gets a binding for the given key.
49 */
50 <T> Binding<T> getBinding(Key<T> key);
crazyboblee62fcdde2007-02-03 02:10:13 +000051
52 /**
53 * Finds all bindings to the given type.
54 */
55 <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type);
crazybobleea3b0c052007-02-03 08:53:46 +000056
57 /**
crazyboblee1814fa42007-02-03 09:28:36 +000058 * Gets the factory bound to the given type.
crazybobleea3b0c052007-02-03 08:53:46 +000059 */
60 <T> Factory<T> getFactory(Class<T> type);
61
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(TypeLiteral<T> type);
crazyboblee1814fa42007-02-03 09:28:36 +000066
67 /**
68 * Gets an instance from the factory bound to the given type.
69 */
70 <T> T getInstance(TypeLiteral<T> type);
71
72 /**
73 * Gets an instance from the factory bound to the given type.
74 */
75 <T> T getInstance(Class<T> type);
76
77 /**
78 * Gets an instance from the factory bound to the given key.
79 */
80 <T> T getInstance(Key<T> key);
crazybobleee5fbbb02007-02-05 07:00:27 +000081
82 /**
crazyboblee4602a6f2007-02-15 02:45:18 +000083 * Gets an instance from the factory bound to the given type and annotation.
crazybobleee5fbbb02007-02-05 07:00:27 +000084 */
crazyboblee4602a6f2007-02-15 02:45:18 +000085 <T> T getInstance(TypeLiteral<T> type,
86 Annotation annotation);
crazybobleee5fbbb02007-02-05 07:00:27 +000087
88 /**
crazyboblee4602a6f2007-02-15 02:45:18 +000089 * Gets an instance from the factory bound to the given type and annotation.
crazybobleee5fbbb02007-02-05 07:00:27 +000090 */
crazyboblee4602a6f2007-02-15 02:45:18 +000091 <T> T getInstance(Class<T> type,
92 Annotation annotation);
crazybobleee5fbbb02007-02-05 07:00:27 +000093
94 /**
crazyboblee4602a6f2007-02-15 02:45:18 +000095 * Gets the factory bound to the given type and annotation.
crazybobleee5fbbb02007-02-05 07:00:27 +000096 */
crazyboblee4602a6f2007-02-15 02:45:18 +000097 <T> Factory<T> getFactory(Class<T> type,
98 Annotation annotation);
crazybobleee5fbbb02007-02-05 07:00:27 +000099
100 /**
crazyboblee4602a6f2007-02-15 02:45:18 +0000101 * Gets the factory bound to the given type and annotation.
crazybobleee5fbbb02007-02-05 07:00:27 +0000102 */
crazyboblee4602a6f2007-02-15 02:45:18 +0000103 <T> Factory<T> getFactory(TypeLiteral<T> type,
104 Annotation annotation);
105
106 /**
107 * Gets an instance from the factory bound to the given type and annotation.
108 */
109 <T> T getInstance(TypeLiteral<T> type,
110 Class<? extends Annotation> annotationType);
111
112 /**
113 * Gets an instance from the factory bound to the given type and annotation.
114 */
115 <T> T getInstance(Class<T> type,
116 Class<? extends Annotation> annotationType);
117
118 /**
119 * Gets the factory bound to the given type and annotation.
120 */
121 <T> Factory<T> getFactory(Class<T> type,
122 Class<? extends Annotation> annotationType);
123
124 /**
125 * Gets the factory bound to the given type and annotation.
126 */
127 <T> Factory<T> getFactory(TypeLiteral<T> type,
128 Class<? extends Annotation> annotationType);
crazyboblee66b415a2006-08-25 02:01:19 +0000129}