Created
October 18, 2012 17:18
-
-
Save alecmce/3913432 to your computer and use it in GitHub Desktop.
enables SignalCommandMapExtension to work across modular contexts
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 robotlegs.bender.extensions.signalCommandMap | |
{ | |
import flash.utils.Dictionary; | |
import org.swiftsuspenders.Injector; | |
import org.swiftsuspenders.dependencyproviders.DependencyProvider; | |
import robotlegs.bender.extensions.commandCenter.api.ICommandCenter; | |
import robotlegs.bender.extensions.signalCommandMap.impl.SignalCommandMap; | |
public class SignalCommandMapPerModuleProvider implements DependencyProvider | |
{ | |
private static const injectorMap:Dictionary = new Dictionary(true); | |
public function apply(targetType:Class, activeInjector:Injector, injectParameters:Dictionary):Object | |
{ | |
return injectorMap[activeInjector] ||= makeSignalCommandMap(activeInjector); | |
} | |
private function makeSignalCommandMap(activeInjector:Injector):SignalCommandMap | |
{ | |
var commandCenter:ICommandCenter = activeInjector.getInstance(ICommandCenter); | |
return new SignalCommandMap(activeInjector, commandCenter); | |
} | |
public function destroy():void {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case:
Main.constructor()
{
parentContext = new Context();
parentContext.extend(MVCSBundle, SignalCommandMapExtension);
parentContext.config(this);
}
ChildConfig.configure()
{
injector.map(Example);
signalCommandMap.map(ExampleSignal).toCommand(ExampleCommand);
}
ExampleCommand
{
[Inject]
public var injected:Example;
}
Not sure if this is just because the SignalCommandMap is doing it wrong, but in order for this to work I need to define the ISignalCommandMap.toProvider(new SignalCommandMapPerModuleProvider()) so that each module gets its own SignalCommandMap (with its own injector) so the local injection mappings are available.