私の Robotlegs アプリの一部のサービスにはパラメーターが必要です。どちらのソリューションが優れているか疑問に思っています:
- メディエーターはパラメーターをサービスに渡します
- サービスは、注入されたモデルからパラメータを取得します
私の Robotlegs アプリの一部のサービスにはパラメーターが必要です。どちらのソリューションが優れているか疑問に思っています:
Creynders が示唆したように、変数が const、モデル、またはユーザー入力であるかどうかは、これらの変数のスコープに依存します。
私にとって素晴らしいリソースは、RobotLegs の ActionScript 開発者ガイドです。
これは私の通常のワークフローです:
Command はサービスを呼び出し、必要なパラメーターを渡します。以下の例では、変数を LoadLicenseEvent と ITokenModel からサービス呼び出しに渡しています。commandMap.detain() と commandMap.release() を使用して、サービス呼び出しが完了するまでコマンドを存続させます。基本クラス ServiceModuleCommand は、障害イベントを処理します。
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);
}