Created
September 23, 2010 04:00
-
-
Save troygilbert/593067 to your computer and use it in GitHub Desktop.
Demonstrate private injection for DI
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 characters
package | |
{ | |
import private_injection; | |
class ClassWithPrivateInjection | |
{ | |
include "inject.include.as"; | |
private var mySecretWord:String; | |
public function speakSecretWord():void | |
{ | |
trace(mySecretWord); | |
} | |
} | |
} |
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 characters
package | |
{ | |
public function doPrivateInjection(instance:*, name:String, value:*):void | |
{ | |
try | |
{ | |
instance.private_injection::injectPrivates(name, value); | |
} | |
catch (e:Error) | |
{ | |
// do nothing, ignore errors | |
} | |
} | |
} |
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 characters
private_injection function injectPrivates(name:String, value:*):void | |
{ | |
try | |
{ | |
this[name] = value; | |
} | |
catch (e:Error) | |
{ | |
// ignore errors, do nothing | |
} | |
} |
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 characters
package | |
{ | |
public namespace private_injection; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment