Parsley provides dynamic commands feature where it creates a new instance of command on triggering of a matching event. Dynamic commands means the command instances which will be created dynamically by Parsley at runtime, whenever it finds any event in the system matching with 'selector' attribute of the command.
So instance of the dynamic command is dependent on the system state. If at anytime, the required event has been fired, the parsley will create the instance of corresponding Command and will handover the event to it.
Dynamic Commands can be singleton or non-singleton. This behavior can be controlled by setting 'singleton' attribute with configuration file while defining the Dynamic Commands. In case of singleton commands, Parsley retain the instance of Dynamic Command once it is generated and always hand over the event to same instance. However for non-singleton command, Parsley creates a new instance of Command every time it gets a matching event.
One should use 'selector', 'execute', 'error', 'result', and 'singleton' attributes while defining the dynamic commands with configuration file. Alternative approach is to write these tags in code file on the methods. We found that sometime 'error' tag specified with code file is not working properly, hence we followed the configuration file approach.
Execute function of the command can return 'void', 'AsyncToken' or a 'Task'. We assume that command is interacting with service for some database interaction or for business logic.
- void - If service is not returning anything, return type can be void for command execute method.
- AsyncToken - If it is returning a asynchronous response, an AsyncToken should be returned. It will invoke the command result and fault handlers whenever it will get the result.
- Task - If we want to execute some task on command result, one can return the Task object which can perform the required task.
No comments:
Post a Comment