|
FabricationIoC
IoC mechanism for Fabrication actors.
Featured IntroductionWith version 0.7.1 a brand new mechanism is being introduced - IoC for Fabrication actors. It simplyfies the way you can retrieve mediators/proxies instances within body of your classes. RequirementsThis feature needs Fabrication version 0.7.1 or above. Usage ScenariosLet say you have your startupCommand like this one: MyApplicationStartupCommand.as package controller {
import org.puremvc.as3.multicore.interfaces.INotification;
import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
import spark.components.Application;
public class MyApplicationStartupCommand extends SimpleFabricationCommand {
override public function execute(notification:INotification):void
{
registerProxy( MyApplicationProxy1( "MyAppProxy1", { someData:"DataFromProxy1" } );
registerProxy( MyApplicationProxy2( "MyAppProxy2", { someData:"DataFromProxy2" } );
}
}
}and your application mediator, when you want to get reference to one of registered proxies: MyApplicationMediator.as package view {
import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlexMediator;
public class MyApplicationMediator extends FlexMediator {
static public const NAME:String = "MyApplicationMediator";
public function MyApplicationMediator(viewComponent:Object) {
super(NAME, viewComponent);
}
override public function onRegister():void {
super.onRegister();
var myProxy:MyApplicationProxy1 = retrieveProxy( "MyAppProxy1" ) as MyApplicationProxy1;
}
}
}Injection by classUsing new IoC mechanism you can do something like this: MyApplicationMediator.as package view {
import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlexMediator;
public class MyApplicationMediator extends FlexMediator {
static public const NAME:String = "MyApplicationMediator";
[InjectProxy]
public var proxy:MyApplicationProxy;
public function MyApplicationMediator(viewComponent:Object) {
super(NAME, viewComponent);
}
}
}Injection by typeInjecting actors by type ( and it's name ) give you possibility to simple and quick way to switch between instances of same type. For example, we can simply inject instance of some proxy ( IProxy ) named "MyAppProxy1": MyApplicationMediator.as package view {
import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlexMediator;
public class MyApplicationMediator extends FlexMediator {
static public const NAME:String = "MyApplicationMediator";
[InjectProxy(name="MyAppProxy1"]
public var proxy:IProxy;
public function MyApplicationMediator(viewComponent:Object) {
super(NAME, viewComponent);
}
}
}We can change metadata name argument to "MyAppProxy2" to have another instance injected. Additional info
Examples | |
Can we see an example of a mediator being injected?? How would you assign the viewComponent?
doesn't work with FlashApplication? version (in this case would be FabricationMediator?).Does it works Only with FlexMediators? only?
@mellomike I will add a simple example today @k.swisulska You should use FlashMediator? in tour flash application. In 0.7.1 version only FlexMediator? has abbility to inject properties, today version 0.7.2 will be released and FlashMediator? should work also.
RE:0.7.2 While compiling with FlashApplication? (Pure As3)am getting missing resource error: VerifyError?: Error #1014: Nie znaleziono klasy mx.modules::Module. , guess some mx stuff shouldn't be there?
Yes, you're right. I'll fix it, upload a new version and let you know
doesn't work in FlashBuilder4?.
declaring a public var outside the class definition throws an error in flash builder:
Beschreibung Ressource Pfad Position Typ A file found in a source-path can not have more than one externally visible definition.
public var outside class definition won't work in any editor :). There was mistake in example - of course injected filed has to be declared inside class definition. It is fixed now.
sorry, maybe i see some needed dependencies not. but even when inject metadata with public scoped variable is in class definition, i get typeerror 1009: access to null object
i use sdk 3.5 and the latest fabrication swc...
i already studied your examples, but cannot find any difference to my code. i would love to use this feature, cause retrieving stuff from puremvc sucks...
If this is possible, please email me your code so I can quickly find the issue. If it is ok, send it to fabrication@googlecode.com
Looks like Injecting works differently in mediators and commands. Same code: InjectProxy? public var so:SharedObjectProxy?;
fires onRegister method when put in mediator and doesn't when in a command.
Hi, Which version of fabrication do you use? In Command injected items ( proxies, mediators, etc ) should be available in execute method. The most important thing is to remember about super.execute() call.
Hi, sorry for late response, I think I didn't get any reminder on email. It worked, but that makes a question when else do I need to call super.execute (), or more specifically, what does the superclass execute?