01: /*
02: * Copyright (C) 2007 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: */
16:
17: package com.google.inject;
18:
19: import java.util.Arrays;
20:
21: /**
22: * The entry point to the Guice framework. Creates {@link Injector}s from
23: * {@link Module}s.
24: */
25: public final class Guice {
26:
27: private Guice() {
28: }
29:
30: /**
31: * Creates an injector with no explicit bindings.
32: */
33: static Injector createEmptyInjector() {
34: return createInjector();
35: }
36:
37: /**
38: * Creates an injector for the given set of modules.
39: *
40: * @throws CreationException from which you can retrieve the individual error
41: * messages
42: */
43: public static Injector createInjector(Module... modules) {
44: return createInjector(Arrays.asList(modules));
45: }
46:
47: /**
48: * Creates an injector for the given set of modules.
49: *
50: * @throws CreationException from which you can retrieve the individual error
51: * messages
52: */
53: public static Injector createInjector(Iterable<Module> modules) {
54: return createInjector(Stage.DEVELOPMENT, modules);
55: }
56:
57: /**
58: * Creates an injector for the given set of modules, in a given development
59: * stage.
60: *
61: * @throws CreationException from which you can retrieve the individual error
62: * messages.
63: */
64: public static Injector createInjector(Stage stage,
65: Module... modules) {
66: return createInjector(stage, Arrays.asList(modules));
67: }
68:
69: /**
70: * Creates an injector for the given set of modules, in a given development
71: * stage.
72: *
73: * @throws CreationException from which you can retrieve the individual error
74: * messages.
75: */
76: public static Injector createInjector(Stage stage,
77: Iterable<Module> modules) {
78: BinderImpl binder = new BinderImpl(stage);
79: for (Module module : modules) {
80: binder.install(module);
81: }
82: return binder.createInjector();
83: }
84: }
|