kevinb9n | b20cc35 | 2007-03-01 19:35:41 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 17 | package com.google.inject; |
| 18 | |
| 19 | import java.util.Arrays; |
| 20 | |
| 21 | /** |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 22 | * The entry point to the Guice framework. Creates {@link Injector}s from |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 23 | * {@link Module}s. |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 24 | */ |
kevinb9n | e5073a2 | 2007-02-20 18:06:47 +0000 | [diff] [blame] | 25 | public final class Guice { |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 26 | |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 27 | private Guice() {} |
| 28 | |
| 29 | /** |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 30 | * Creates an injector for the given set of modules. |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 31 | */ |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 32 | public static Injector createInjector(Module... modules) |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 33 | throws CreationException { |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 34 | return createInjector(Arrays.asList(modules)); |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 35 | } |
| 36 | |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 37 | /** |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 38 | * Creates an injector for the given set of modules. |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 39 | */ |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 40 | public static Injector createInjector(Iterable<Module> modules) |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 41 | throws CreationException { |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 42 | return createInjector(Stage.DEVELOPMENT, modules); |
kevinb9n | e5073a2 | 2007-02-20 18:06:47 +0000 | [diff] [blame] | 43 | } |
| 44 | |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 45 | /** |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 46 | * Creates an injector for the given set of modules, in a given development |
| 47 | * stage. |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 48 | */ |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 49 | public static Injector createInjector(Stage stage, Module... modules) |
kevinb9n | e5073a2 | 2007-02-20 18:06:47 +0000 | [diff] [blame] | 50 | throws CreationException { |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 51 | return createInjector(stage, Arrays.asList(modules)); |
kevinb9n | e5073a2 | 2007-02-20 18:06:47 +0000 | [diff] [blame] | 52 | } |
| 53 | |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 54 | /** |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 55 | * Creates an injector for the given set of modules, in a given development |
| 56 | * stage. |
crazyboblee | 0bfdbc6 | 2007-02-20 21:47:19 +0000 | [diff] [blame] | 57 | */ |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 58 | public static Injector createInjector(Stage stage, Iterable<Module> modules) |
kevinb9n | e5073a2 | 2007-02-20 18:06:47 +0000 | [diff] [blame] | 59 | throws CreationException { |
| 60 | BinderImpl binder = new BinderImpl(stage); |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 61 | for (Module module : modules) { |
| 62 | binder.install(module); |
| 63 | } |
kevinb9n | a2915a9 | 2007-02-28 06:20:30 +0000 | [diff] [blame] | 64 | return binder.createInjector(); |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 65 | } |
kevinb9n | db85d9c | 2007-02-20 05:23:46 +0000 | [diff] [blame] | 66 | } |