MVVM Messenger Pattern. How does it work?
Hello there,
I am trying to understand how to implement a messenger in my MVVM application.
The framework I am using is DevExpress's MVVM Framework, which includes a messenger which can be used for passing and subscribing to messages between objects. I presume MVVMLight, Prism, etc all do/have much the same thing.
I am trying to figure out exactly how one goes about making something work using messenging.
Lets take for example. The process of placing an order via a website API. In my application, I have two objects. One that keeps track of the session and webAPI functions. One that knows about orders on a local system.
If I was to do it in a coupled way. I would instantiate on my OrderObject an APIObject and run a method from there...something like APIObject.PlaceOrder...and that method would return a value of success or failure. My OrderObject would then continue on its way, knowing if there was successful ordering or not....
In a messenging bus pattern, or an uncoupled way. I wonder how to achieve the same thing. I presume that in the OrderObject I would send a message that an order is ready to be placed..... The APIObject would be listening to the messagebus for new orders and place an order according to the message when it comes.
How then does the OrderObject know whether the order was successful or not? It doesn;t know about APIObject? And how does it know when to resume processing?
On a side note, if anyone could tell me what the most commonly used pattern name for a Messenger like devexpress'? Is it a mediator, observer, or some other named pattern?
I'd be very appreciative if anyone could offer any advice? Thank you
0 comments:
Post a Comment