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 14
14
<artifactId >junit</artifactId >
15
15
<scope >test</scope >
16
16
</dependency >
17
+ <dependency >
18
+ <groupId >com.google.inject</groupId >
19
+ <artifactId >guice</artifactId >
20
+ <version >4.0</version >
21
+ </dependency >
17
22
</dependencies >
18
23
</project >
Original file line number Diff line number Diff line change 1
1
package com .iluwatar ;
2
2
3
+ import com .google .inject .Guice ;
4
+ import com .google .inject .Injector ;
5
+
3
6
public class App {
4
7
5
8
public static void main ( String [] args ) {
@@ -8,5 +11,9 @@ public static void main( String[] args ) {
8
11
9
12
AdvancedWizard advancedWizard = new AdvancedWizard (new SecondBreakfastTobacco ());
10
13
advancedWizard .smoke ();
14
+
15
+ Injector injector = Guice .createInjector (new TobaccoModule ());
16
+ GuiceWizard guiceWizard = injector .getInstance (GuiceWizard .class );
17
+ guiceWizard .smoke ();
11
18
}
12
19
}
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