Skip to content

Commit

Permalink
Finished the example.
Browse files Browse the repository at this point in the history
  • Loading branch information
iluwatar committed May 25, 2015
1 parent b2bfdb1 commit fdf1d14
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dependency-injection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
</project>
7 changes: 7 additions & 0 deletions dependency-injection/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.iluwatar;

import com.google.inject.Guice;
import com.google.inject.Injector;

public class App {

public static void main( String[] args ) {
Expand All @@ -8,5 +11,9 @@ public static void main( String[] args ) {

AdvancedWizard advancedWizard = new AdvancedWizard(new SecondBreakfastTobacco());
advancedWizard.smoke();

Injector injector = Guice.createInjector(new TobaccoModule());
GuiceWizard guiceWizard = injector.getInstance(GuiceWizard.class);
guiceWizard.smoke();
}
}
18 changes: 18 additions & 0 deletions dependency-injection/src/main/java/com/iluwatar/GuiceWizard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.iluwatar;

import javax.inject.Inject;

public class GuiceWizard implements Wizard {

private Tobacco tobacco;

@Inject
public GuiceWizard(Tobacco tobacco) {
this.tobacco = tobacco;
}

@Override
public void smoke() {
tobacco.smoke(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.iluwatar;

public class RivendellTobacco extends Tobacco {
}
11 changes: 11 additions & 0 deletions dependency-injection/src/main/java/com/iluwatar/TobaccoModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.iluwatar;

import com.google.inject.AbstractModule;

public class TobaccoModule extends AbstractModule {

@Override
protected void configure() {
bind(Tobacco.class).to(RivendellTobacco.class);
}
}

0 comments on commit fdf1d14

Please sign in to comment.