blob: f06e5e33f1c1eadd00a57866b686e378645efd02 [file] [log] [blame]
kevinb9nb20cc352007-03-01 19:35:41 +00001/*
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
kevinb9ndb85d9c2007-02-20 05:23:46 +000017package com.google.inject;
18
19import java.util.Arrays;
20
21/**
kevinb9na2915a92007-02-28 06:20:30 +000022 * The entry point to the Guice framework. Creates {@link Injector}s from
crazyboblee0bfdbc62007-02-20 21:47:19 +000023 * {@link Module}s.
kevinb9ndb85d9c2007-02-20 05:23:46 +000024 */
kevinb9ne5073a22007-02-20 18:06:47 +000025public final class Guice {
kevinb9ndb85d9c2007-02-20 05:23:46 +000026
crazyboblee0bfdbc62007-02-20 21:47:19 +000027 private Guice() {}
28
29 /**
kevinb9na2915a92007-02-28 06:20:30 +000030 * Creates an injector for the given set of modules.
crazyboblee0bfdbc62007-02-20 21:47:19 +000031 */
kevinb9na2915a92007-02-28 06:20:30 +000032 public static Injector createInjector(Module... modules)
kevinb9ndb85d9c2007-02-20 05:23:46 +000033 throws CreationException {
kevinb9na2915a92007-02-28 06:20:30 +000034 return createInjector(Arrays.asList(modules));
kevinb9ndb85d9c2007-02-20 05:23:46 +000035 }
36
crazyboblee0bfdbc62007-02-20 21:47:19 +000037 /**
kevinb9na2915a92007-02-28 06:20:30 +000038 * Creates an injector for the given set of modules.
crazyboblee0bfdbc62007-02-20 21:47:19 +000039 */
kevinb9na2915a92007-02-28 06:20:30 +000040 public static Injector createInjector(Iterable<Module> modules)
kevinb9ndb85d9c2007-02-20 05:23:46 +000041 throws CreationException {
kevinb9na2915a92007-02-28 06:20:30 +000042 return createInjector(Stage.DEVELOPMENT, modules);
kevinb9ne5073a22007-02-20 18:06:47 +000043 }
44
crazyboblee0bfdbc62007-02-20 21:47:19 +000045 /**
kevinb9na2915a92007-02-28 06:20:30 +000046 * Creates an injector for the given set of modules, in a given development
47 * stage.
crazyboblee0bfdbc62007-02-20 21:47:19 +000048 */
kevinb9na2915a92007-02-28 06:20:30 +000049 public static Injector createInjector(Stage stage, Module... modules)
kevinb9ne5073a22007-02-20 18:06:47 +000050 throws CreationException {
kevinb9na2915a92007-02-28 06:20:30 +000051 return createInjector(stage, Arrays.asList(modules));
kevinb9ne5073a22007-02-20 18:06:47 +000052 }
53
crazyboblee0bfdbc62007-02-20 21:47:19 +000054 /**
kevinb9na2915a92007-02-28 06:20:30 +000055 * Creates an injector for the given set of modules, in a given development
56 * stage.
crazyboblee0bfdbc62007-02-20 21:47:19 +000057 */
kevinb9na2915a92007-02-28 06:20:30 +000058 public static Injector createInjector(Stage stage, Iterable<Module> modules)
kevinb9ne5073a22007-02-20 18:06:47 +000059 throws CreationException {
60 BinderImpl binder = new BinderImpl(stage);
kevinb9ndb85d9c2007-02-20 05:23:46 +000061 for (Module module : modules) {
62 binder.install(module);
63 }
kevinb9na2915a92007-02-28 06:20:30 +000064 return binder.createInjector();
kevinb9ndb85d9c2007-02-20 05:23:46 +000065 }
kevinb9ndb85d9c2007-02-20 05:23:46 +000066}