This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for child injectors, enabling usage of different inject…
…ion mappings for parts of a dependency tree In addition, injection results classes have been refactored to inherit from a base class instead of implementing an interface to facilitate code-reuse
- Loading branch information
1 parent
b9510f0
commit c63091d
Showing
15 changed files
with
261 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
38 changes: 38 additions & 0 deletions
38
src/org/swiftsuspenders/injectionresults/InjectionResult.as
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2009 the original author or authors | ||
* | ||
* Permission is hereby granted to use, modify, and distribute this file | ||
* in accordance with the terms of the license agreement accompanying it. | ||
*/ | ||
|
||
package org.swiftsuspenders.injectionresults | ||
{ | ||
import org.swiftsuspenders.Injector; | ||
|
||
public class InjectionResult | ||
{ | ||
/******************************************************************************************* | ||
* protected properties * | ||
*******************************************************************************************/ | ||
protected var m_injector : Injector; | ||
|
||
|
||
/******************************************************************************************* | ||
* public methods * | ||
*******************************************************************************************/ | ||
public function InjectionResult(injector : Injector) | ||
{ | ||
m_injector = injector; | ||
} | ||
|
||
public function getResponse() : Object | ||
{ | ||
return null; | ||
} | ||
|
||
public function setInjector(injector : Injector) : void | ||
{ | ||
m_injector = injector; | ||
} | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2009 the original author or authors | ||
* | ||
* Permission is hereby granted to use, modify, and distribute this file | ||
* in accordance with the terms of the license agreement accompanying it. | ||
*/ | ||
|
||
package org.swiftsuspenders | ||
{ | ||
import flexunit.framework.Assert; | ||
|
||
import org.swiftsuspenders.support.injectees.childinjectors.LeftRobotFoot; | ||
import org.swiftsuspenders.support.injectees.childinjectors.RightRobotFoot; | ||
import org.swiftsuspenders.support.injectees.childinjectors.RobotBody; | ||
import org.swiftsuspenders.support.injectees.childinjectors.RobotFoot; | ||
import org.swiftsuspenders.support.injectees.childinjectors.RobotLeg; | ||
import org.swiftsuspenders.support.injectees.childinjectors.RobotToes; | ||
|
||
public class ChildInjectorTests | ||
{ | ||
protected var injector:Injector; | ||
|
||
[Before] | ||
public function runBeforeEachTest():void | ||
{ | ||
injector = new Injector(); | ||
} | ||
|
||
[Test] | ||
public function injectorCreatesChildInjector() : void | ||
{ | ||
Assert.assertTrue(true); | ||
var childInjector : Injector = injector.createChildInjector(); | ||
Assert.assertTrue('injector.createChildInjector should return an injector', | ||
childInjector is Injector); | ||
} | ||
|
||
[Test] | ||
public function injectorUsesChildInjectorForSpecifiedRule() : void | ||
{ | ||
injector.mapClass(RobotFoot, RobotFoot); | ||
|
||
var leftFootRule : InjectionConfig = injector.mapClass(RobotLeg, RobotLeg, 'leftLeg'); | ||
var leftChildInjector : Injector = injector.createChildInjector(); | ||
leftChildInjector.mapClass(RobotFoot, LeftRobotFoot); | ||
leftFootRule.setInjector(leftChildInjector); | ||
|
||
var rightFootRule : InjectionConfig = injector.mapClass(RobotLeg, RobotLeg, 'rightLeg'); | ||
var rightChildInjector : Injector = injector.createChildInjector(); | ||
rightChildInjector.mapClass(RobotFoot, RightRobotFoot); | ||
rightFootRule.setInjector(rightChildInjector); | ||
|
||
var robotBody : RobotBody = injector.instantiate(RobotBody); | ||
|
||
Assert.assertTrue('Right RobotLeg should have a RightRobotFoot', | ||
robotBody.rightLeg.foot is RightRobotFoot); | ||
Assert.assertTrue('Left RobotLeg should have a LeftRobotFoot', | ||
robotBody.leftLeg.foot is LeftRobotFoot); | ||
} | ||
|
||
[Test] | ||
public function childInjectorUsesParentInjectorForMissingRules() : void | ||
{ | ||
injector.mapClass(RobotFoot, RobotFoot); | ||
injector.mapClass(RobotToes, RobotToes); | ||
|
||
var leftFootRule : InjectionConfig = injector.mapClass(RobotLeg, RobotLeg, 'leftLeg'); | ||
var leftChildInjector : Injector = injector.createChildInjector(); | ||
leftChildInjector.mapClass(RobotFoot, LeftRobotFoot); | ||
leftFootRule.setInjector(leftChildInjector); | ||
|
||
var rightFootRule : InjectionConfig = injector.mapClass(RobotLeg, RobotLeg, 'rightLeg'); | ||
var rightChildInjector : Injector = injector.createChildInjector(); | ||
rightChildInjector.mapClass(RobotFoot, RightRobotFoot); | ||
rightFootRule.setInjector(rightChildInjector); | ||
|
||
var robotBody : RobotBody = injector.instantiate(RobotBody); | ||
|
||
Assert.assertTrue('Right RobotFoot should have toes', | ||
robotBody.rightLeg.foot.toes is RobotToes); | ||
Assert.assertTrue('Left Robotfoot should have a toes', | ||
robotBody.leftLeg.foot.toes is RobotToes); | ||
} | ||
} | ||
} |
This file contains 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 characters
17 changes: 17 additions & 0 deletions
17
test/org/swiftsuspenders/support/injectees/childinjectors/LeftRobotFoot.as
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2009 the original author or authors | ||
* | ||
* Permission is hereby granted to use, modify, and distribute this file | ||
* in accordance with the terms of the license agreement accompanying it. | ||
*/ | ||
|
||
package org.swiftsuspenders.support.injectees.childinjectors | ||
{ | ||
public class LeftRobotFoot extends RobotFoot | ||
{ | ||
public function LeftRobotFoot(toes : RobotToes = null) | ||
{ | ||
super(toes); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/org/swiftsuspenders/support/injectees/childinjectors/RightRobotFoot.as
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2009 the original author or authors | ||
* | ||
* Permission is hereby granted to use, modify, and distribute this file | ||
* in accordance with the terms of the license agreement accompanying it. | ||
*/ | ||
|
||
package org.swiftsuspenders.support.injectees.childinjectors | ||
{ | ||
public class RightRobotFoot extends RobotFoot | ||
{ | ||
public function RightRobotFoot(toes : RobotToes = null) | ||
{ | ||
super(toes); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/org/swiftsuspenders/support/injectees/childinjectors/RobotBody.as
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2009 the original author or authors | ||
* | ||
* Permission is hereby granted to use, modify, and distribute this file | ||
* in accordance with the terms of the license agreement accompanying it. | ||
*/ | ||
|
||
package org.swiftsuspenders.support.injectees.childinjectors | ||
{ | ||
public class RobotBody | ||
{ | ||
[Inject(name='leftLeg')] | ||
public var leftLeg : RobotLeg; | ||
|
||
[Inject(name='rightLeg')] | ||
public var rightLeg : RobotLeg; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
test/org/swiftsuspenders/support/injectees/childinjectors/RobotFoot.as
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2009 the original author or authors | ||
* | ||
* Permission is hereby granted to use, modify, and distribute this file | ||
* in accordance with the terms of the license agreement accompanying it. | ||
*/ | ||
|
||
package org.swiftsuspenders.support.injectees.childinjectors | ||
{ | ||
public class RobotFoot | ||
{ | ||
public var toes : RobotToes; | ||
|
||
public function RobotFoot(toes : RobotToes = null) | ||
{ | ||
this.toes = toes; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/org/swiftsuspenders/support/injectees/childinjectors/RobotLeg.as
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2009 the original author or authors | ||
* | ||
* Permission is hereby granted to use, modify, and distribute this file | ||
* in accordance with the terms of the license agreement accompanying it. | ||
*/ | ||
|
||
package org.swiftsuspenders.support.injectees.childinjectors | ||
{ | ||
public class RobotLeg | ||
{ | ||
[Inject] | ||
public var foot : RobotFoot; | ||
} | ||
} |
Oops, something went wrong.