diff --git a/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/PartOne.java b/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/BasicInjection.java similarity index 89% rename from src/main/java/org/matsim/codeexamples/guicewithoutmatsim/PartOne.java rename to src/main/java/org/matsim/codeexamples/guicewithoutmatsim/BasicInjection.java index a5e81c23..42664eb8 100644 --- a/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/PartOne.java +++ b/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/BasicInjection.java @@ -4,13 +4,11 @@ import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; -import com.google.inject.multibindings.MapBinder; -import com.google.inject.multibindings.MultibinderBinding; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; -class PartOne{ - private static final Logger log = LogManager.getLogger( PartOne.class ) ; +class BasicInjection{ + private static final Logger log = LogManager.getLogger( BasicInjection.class ) ; public static void main(String[] args){ Injector injector = Guice.createInjector( new AbstractModule(){ diff --git a/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/ConstructorInjection.java b/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/ConventionalInjectionByConstructor.java similarity index 87% rename from src/main/java/org/matsim/codeexamples/guicewithoutmatsim/ConstructorInjection.java rename to src/main/java/org/matsim/codeexamples/guicewithoutmatsim/ConventionalInjectionByConstructor.java index 43e20730..42693de6 100644 --- a/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/ConstructorInjection.java +++ b/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/ConventionalInjectionByConstructor.java @@ -1,12 +1,11 @@ package org.matsim.codeexamples.guicewithoutmatsim; -import com.google.inject.Inject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -class ConstructorInjection{ +class ConventionalInjectionByConstructor{ - private static final Logger log = LogManager.getLogger( org.matsim.codeexamples.guicewithoutmatsim.PartOne.class ) ; + private static final Logger log = LogManager.getLogger( BasicInjection.class ) ; public static void main(String[] args){ Helper helper = new MyHelper1(); diff --git a/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/GuiceTester.java b/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/GuiceTester.java deleted file mode 100644 index 4248af9e..00000000 --- a/src/main/java/org/matsim/codeexamples/guicewithoutmatsim/GuiceTester.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.matsim.codeexamples.guicewithoutmatsim; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.ImplementedBy; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.name.Named; -import com.google.inject.name.Names; - -public class GuiceTester { - public static void main(String[] args) { - Injector injector = Guice.createInjector(new TextEditorModule()); - TextEditor editor = injector.getInstance(TextEditor.class); - editor.makeSpellCheck(); - } -} - -class TextEditor { - private SpellChecker spellChecker; - - @Inject - public TextEditor( SpellChecker spellChecker) { - this.spellChecker = spellChecker; - } - public void makeSpellCheck() { - spellChecker.checkSpelling(); - } -} - -//Binding Module -class TextEditorModule extends AbstractModule { - @Override protected void configure() { - bind(String.class).annotatedWith(Names.named("JDBC")).toInstance("jdbc:mysql://localhost:5326/emp"); - bind( SpellChecker.class ).to( SpellCheckerImpl.class ) ; - } -} - -//@ImplementedBy(SpellCheckerImpl.class) -interface SpellChecker { - public void checkSpelling(); -} - -//spell checker implementation -class SpellCheckerImpl implements SpellChecker { - private String dbUrl; - public SpellCheckerImpl(){} - - @Inject - public void setDbUrl(@Named("JDBC") String dbUrl) { - this.dbUrl = dbUrl; - } - @Override - public void checkSpelling() { - System.out.println("Inside checkSpelling." ); - System.out.println(dbUrl); - } -}