Created
October 6, 2010 21:00
-
-
Save darscan/614078 to your computer and use it in GitHub Desktop.
Initial stab at a Dawn Adapter for Robotlegs
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
package org.robotlegs.adapters | |
{ | |
import flash.system.ApplicationDomain; | |
import org.robotlegs.core.IInjector; | |
import uk.co.ziazoo.injector.IInjector; | |
import uk.co.ziazoo.injector.impl.Injector; | |
public class DawnInjector implements org.robotlegs.core.IInjector | |
{ | |
protected var injector:uk.co.ziazoo.injector.IInjector; | |
public function DawnInjector(injector:uk.co.ziazoo.injector.IInjector = null) | |
{ | |
this.injector = injector || Injector.createInjector(); | |
} | |
public function mapValue(whenAskedFor:Class, useValue:Object, named:String = ""):* | |
{ | |
return injector.map(whenAskedFor).toInstance(useValue).named(named); | |
} | |
public function mapClass(whenAskedFor:Class, instantiateClass:Class, named:String = ""):* | |
{ | |
return injector.map(whenAskedFor).to(instantiateClass).named(named); | |
} | |
public function mapSingleton(whenAskedFor:Class, named:String = ""):* | |
{ | |
return injector.map(whenAskedFor).named(named).asSingleton(); | |
} | |
public function mapSingletonOf(whenAskedFor:Class, useSingletonOf:Class, named:String = ""):* | |
{ | |
return injector.map(whenAskedFor).to(useSingletonOf).named(named).asSingleton(); | |
} | |
public function mapRule(whenAskedFor:Class, useRule:*, named:String = ""):* | |
{ | |
throw(new Error('mapRule not implemented')); | |
return null; | |
} | |
public function injectInto(target:Object):void | |
{ | |
injector.inject(target); | |
} | |
public function instantiate(clazz:Class):* | |
{ | |
trace('WARNING: instantiate is probably wrong'); | |
// return injector.inject(clazz); | |
return injector.inject(new clazz()); | |
} | |
public function getInstance(clazz:Class, named:String = ""):* | |
{ | |
trace('WARNING: can not retrieve named dependecy - ' + named); | |
return injector.inject(clazz); | |
} | |
public function createChild(applicationDomain:ApplicationDomain = null):IInjector | |
{ | |
trace('WARNING: returning self for createChild call'); | |
return this; | |
} | |
public function unmap(clazz:Class, named:String = ""):void | |
{ | |
trace('WARNING: can not unmap'); | |
} | |
public function hasMapping(clazz:Class, named:String = ""):Boolean | |
{ | |
trace('WARNING: can not check for existing mappings'); | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment