/sandbox/guice-sandbox/src/examples/Main6.java
http://t-2.googlecode.com/ · Java · 37 lines · 29 code · 8 blank · 0 comment · 0 complexity · 17fac66191b9d8b90c0f4b21c5983b1d MD5 · raw file
- package examples;
-
- import com.google.inject.AbstractModule;
- import com.google.inject.Guice;
- import com.google.inject.Injector;
- import com.google.inject.Module;
-
- public class Main6 {
-
- public static void main(String[] args) {
- Module module1 = new AbstractModule() {
-
- @Override
- protected void configure() {
- bind(Bar.class);
- bind(Hoge.class).toInstance(new Hoge("mukya!"));
- }
-
- };
- Module module2 = new AbstractModule() {
-
- @Override
- protected void configure() {
- bind(Foo.class).to(FooImpl.class);
- }
-
- };
- Injector injector = Guice.createInjector(module1, module2);
- Bar bar = injector.getInstance(Bar.class);
- System.out.println(bar.getMessage());
- System.out.println(bar.getMessage());
-
- Foo foo = injector.getInstance(Foo.class);
- System.out.println(foo.message());
- System.out.println(foo.num());
- }
- }