File tree Expand file tree Collapse file tree 5 files changed +45
-0
lines changed
src/main/java/com/iluwatar Expand file tree Collapse file tree 5 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1414 <artifactId >junit</artifactId >
1515 <scope >test</scope >
1616 </dependency >
17+ <dependency >
18+ <groupId >com.google.inject</groupId >
19+ <artifactId >guice</artifactId >
20+ <version >4.0</version >
21+ </dependency >
1722 </dependencies >
1823</project >
Original file line number Diff line number Diff line change 11package com .iluwatar ;
22
3+ import com .google .inject .Guice ;
4+ import com .google .inject .Injector ;
5+
36public class App {
47
58 public static void main ( String [] args ) {
@@ -8,5 +11,9 @@ public static void main( String[] args ) {
811
912 AdvancedWizard advancedWizard = new AdvancedWizard (new SecondBreakfastTobacco ());
1013 advancedWizard .smoke ();
14+
15+ Injector injector = Guice .createInjector (new TobaccoModule ());
16+ GuiceWizard guiceWizard = injector .getInstance (GuiceWizard .class );
17+ guiceWizard .smoke ();
1118 }
1219}
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ import javax .inject .Inject ;
4+
5+ public class GuiceWizard implements Wizard {
6+
7+ private Tobacco tobacco ;
8+
9+ @ Inject
10+ public GuiceWizard (Tobacco tobacco ) {
11+ this .tobacco = tobacco ;
12+ }
13+
14+ @ Override
15+ public void smoke () {
16+ tobacco .smoke (this );
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class RivendellTobacco extends Tobacco {
4+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ import com .google .inject .AbstractModule ;
4+
5+ public class TobaccoModule extends AbstractModule {
6+
7+ @ Override
8+ protected void configure () {
9+ bind (Tobacco .class ).to (RivendellTobacco .class );
10+ }
11+ }
You can’t perform that action at this time.
0 commit comments