Some services in my Robotlegs app require parameters. I'm wondering which solution is better:
As Creynders suggested, it depends on the scope of these variables, if they are const, model, or user input.
A great resource for me has been the ActionScript Developer's Guide to RobotLegs: http://books.google.ca/books/about/ActionScript_Developer_s_Guide_to_Robotl.html?id=PFA2TWqZdSMC&redir_esc=y
This is my usual workflow:
Command calls the service, passing any necessary parameters. In the example below, I am passing a variable from the LoadLicenseEvent and from the ITokenModel to the service call. I use commandMap.detain() and commandMap.release() to keep the command alive until the service call is complete. The base class ServiceModuleCommand handles the fault event.
public class LoadLicenseCommand extends ServiceModuleCommand
{
[Inject]
public var event:LoadLicenseEvent;
[Inject]
public var service:ILicenseService;
[Inject]
public var tokenModel:ITokenModel;
[Inject]
public var licenseModel:ILicenseModel;
public override function execute():void
{
commandMap.detain(this);
var token:TokenVO = tokenModel.getToken();
var asyncToken:AsyncToken = service.getLicense(token.Id, event.id);
asyncToken.addResponder(new mx.rpc.Responder(resultHandler, faultHandler));
}
private function resultHandler(e:ResultEvent):void
{
var license:LicenseWebViewVO = e.result as LicenseWebViewVO;
if (license)
{
licenseModel.license = license;
dispatchToModules(new RunWidgetEvent(WidgetType.getWidgetId(WidgetType.LICENSE)));
}
commandMap.release(this);
}