We have discussed various design for various layers in MVCS. Another approach is:
- View are having reference of Presentation Model. Better to inject the PM using Parsley DI, however as per requirement, these can be instantiated using constructor also.
- Commands are having reference of Service. Services are injected using DI.
- Commands are dynamic and non-singleton in nature, and hence every event will result in creation of a new command. Parsley framework will automatically create a new command for every event, and hand over the event to it.
- View can interact with commands using events, and can pass the PM to commands by putting it in Event.
- As commands are non-singleton and existing one per event, so now commands can retain the instance of PM till these get the response back from asynchronous service request in result handler. In result handler, command can use the retained PM and update the state of the PM and hence of the view.
- Command can interact with view or Model using events. However Model and View need to put the check for the events to filter out the events targeted for other UI of same type.It can be done by putting a check for the PM, as command are having the instance of PM, so same can be passed to view or model with event to filter the required event.
This design considers all the features given by Parsley and Flex and provide flexibility in terms of interaction among layers.