Created
August 12, 2011 03:01
-
-
Save coderunner/1141345 to your computer and use it in GitHub Desktop.
Revisions
-
coderunner revised this gist
Aug 12, 2011 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,8 @@ public void initInject() { //setup injection bindings, this is done once at initialization Injector.Builder builder = new Injector.Builder(); injector = builder .addClassBinding(AnotherDependencyInterface.class, AnotherDependency.class) .addClassBinding(DependencyInterface.class, Dependency.class) .addClassBinding(ExampleClass.class, ExampleClass.class) .build(); -
coderunner revised this gist
Aug 12, 2011 . 1 changed file with 42 additions and 45 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,55 +2,52 @@ public class MainClass { private Injector injector; /** MANUAL OBJECT TREE SETUP **/ public void manualObjectTreeSetup() { //create the dependency tree //this can get really annoying AnotherDependencyInterface anotherDependency = new AnotherDependency(); DependencyInterface dependency = new Dependency(anotherDependency); //create the object ExampleClass object = new ExampleClass(dependency); } /** USING DEPENDENCY INJECTION **/ public void initInject() { //setup injection bindings, this is done once at initialization Injector.Builder builder = new Injector.Builder(); injector = builder.addClassBinding(AnotherDependencyInterface.class, AnotherDependency.class) .addClassBinding(DependencyInterface.class, Dependency.class) .addClassBinding(ExampleClass.class, ExampleClass.class) .build(); } public void injectObjectTreeSetup() { //create the required object //the injector will create the require dependencies and inject //them in the newly create instance ExampleClass object = injector.createObject(ExampleClass.class); } /** MAIN **/ public static void main(String args[]) { MainClass main = new MainClass(); //manual setup main.manualObjectTreeSetup(); //using DI library main.initInject(); main.injectObjectTreeSetup(); } } -
coderunner revised this gist
Aug 12, 2011 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,10 @@ import org.inject.Injector; public class MainClass { private Injector injector; /** MANUAL OBJECT TREE SETUP **/ public void manualObjectTreeSetup() { //create the dependency tree @@ -16,7 +19,8 @@ public void manualObjectTreeSetup() ExampleClass object = new ExampleClass(dependency); } /** USING DEPENDENCY INJECTION **/ public void initInject() { //setup injection bindings, this is done once at initialization Injector.Builder builder = new Injector.Builder(); @@ -37,6 +41,7 @@ public void injectObjectTreeSetup() ExampleClass object = injector.createObject(ExampleClass.class); } /** MAIN **/ public static void main(String args[]) { MainClass main = new MainClass(); @@ -45,7 +50,7 @@ public static void main(String args[]) main.manualObjectTreeSetup(); //using DI library main.initInject(); main.injectObjectTreeSetup(); } } -
coderunner created this gist
Aug 12, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ public class MainClass { private Injector injector; public void manualObjectTreeSetup() { //create the dependency tree //this can get really annoying AnotherDependencyInterface anotherDependency = new AnotherDependency(); DependencyInterface dependency = new Dependency(anotherDependency); //create the object ExampleClass object = new ExampleClass(dependency); } public void init() { //setup injection bindings, this is done once at initialization Injector.Builder builder = new Injector.Builder(); injector = builder.addClassBinding(AnotherDependencyInterface.class, AnotherDependency.class) .addClassBinding(DependencyInterface.class, Dependency.class) .addClassBinding(ExampleClass.class, ExampleClass.class) .build(); } public void injectObjectTreeSetup() { //create the required object //the injector will create the require dependencies and inject //them in the newly create instance ExampleClass object = injector.createObject(ExampleClass.class); } public static void main(String args[]) { MainClass main = new MainClass(); //manual setup main.manualObjectTreeSetup(); //using DI library main.init(); main.injectObjectTreeSetup(); } }