Merge remote-tracking branch 'origin/BAEL-2399' into BAEL-2399

This commit is contained in:
emineoymak 2019-01-01 03:09:16 -05:00
commit e62fd6b4fb
1 changed files with 50 additions and 47 deletions

View File

@ -1,47 +1,50 @@
package com.baeldung.examples.guice.modules; package com.baeldung.examples.guice.modules;
import com.baeldung.examples.common.AccountService; import com.baeldung.examples.common.AccountService;
import com.baeldung.examples.common.AccountServiceImpl; import com.baeldung.examples.common.AccountServiceImpl;
import com.baeldung.examples.common.BookService; import com.baeldung.examples.common.BookService;
import com.baeldung.examples.common.BookServiceImpl; import com.baeldung.examples.common.BookServiceImpl;
import com.baeldung.examples.guice.Foo; import com.baeldung.examples.common.PersonDao;
import com.baeldung.examples.guice.Person; import com.baeldung.examples.common.PersonDaoImpl;
import com.google.inject.AbstractModule; import com.baeldung.examples.guice.Foo;
import com.google.inject.Provider; import com.baeldung.examples.guice.Person;
import com.google.inject.Provides; import com.google.inject.AbstractModule;
import com.google.inject.Provider;
public class GuiceModule extends AbstractModule { import com.google.inject.Provides;
@Override public class GuiceModule extends AbstractModule {
protected void configure() {
try { @Override
bind(AccountService.class).to(AccountServiceImpl.class); protected void configure() {
bind(Foo.class).toProvider(new Provider<Foo>() { try {
public Foo get() { bind(PersonDao.class).to(PersonDaoImpl.class);
return null; bind(AccountService.class).to(AccountServiceImpl.class);
} bind(Foo.class).toProvider(new Provider<Foo>() {
}); public Foo get() {
return null;
bind(Person.class).toConstructor(Person.class.getConstructor()); }
// bind(Person.class).toProvider(new Provider<Person>() { });
// public Person get() {
// Person p = new Person(); bind(Person.class).toConstructor(Person.class.getConstructor());
// return p; // bind(Person.class).toProvider(new Provider<Person>() {
// } // public Person get() {
// }); // Person p = new Person();
} catch (NoSuchMethodException e) { // return p;
// TODO Auto-generated catch block // }
e.printStackTrace(); // });
} catch (SecurityException e) { } catch (NoSuchMethodException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} } catch (SecurityException e) {
// TODO Auto-generated catch block
} e.printStackTrace();
}
@Provides
public BookService bookServiceGenerator() { }
return new BookServiceImpl();
} @Provides
public BookService bookServiceGenerator() {
} return new BookServiceImpl();
}
}