Skip to content

Instantly share code, notes, and snippets.

@alecmce
Created October 18, 2012 17:18
Show Gist options
  • Save alecmce/3913432 to your computer and use it in GitHub Desktop.
Save alecmce/3913432 to your computer and use it in GitHub Desktop.
enables SignalCommandMapExtension to work across modular contexts
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 {}
}
}
@alecmce
Copy link
Author

alecmce commented Oct 18, 2012

Use case:

Main.constructor()
{
parentContext = new Context();
parentContext.extend(MVCSBundle, SignalCommandMapExtension);
parentContext.config(this);

childContext = new Context();
childContext.injector.parent = parentContext.injector;
childContext.configure(ChildConfig);
childContext.initialize();

}

ChildConfig.configure()
{
injector.map(Example);
signalCommandMap.map(ExampleSignal).toCommand(ExampleCommand);
}

ExampleCommand
{
[Inject]
public var injected:Example;

execute()
{
    trace(injected); // injected is null because the signalCommandMap's injector is from parentContext not childContext
}

}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment