I am writing an application that listens on a network connection, and when some data arrives, it responds back and depending on the incoming data, you may need to ask the user (show a dialog) before answering back.
I don’t know how to do this in MV-VM architecture: events and binding to observable collections are good if I just need to update the GUI based on the input, but what if I really need anwer from the user before replying back?
And to make things worse, I want to do it synchronously, because I want my answer algorithm to be in one place, and not split into several callbacks with unclear who-called-who responsibilities.
Just something like
HandleMessage(Message msg){ string reply; if (msg.type == 1) { reply = ... } else { string question = msg... reply = ShowModalDialog(question);
but I don’t want to call the view mode or viewmodel from the model, since the model must be reusable and testable - I don’t want dialogs to appear in every test run, and that would be a violation of MVVM! There are no events (they are only one-way, as far as I know, and do not have a return channel to get an answer to the origin of the event) or data binding, as this will be asynchronous.
Is this doable? This is a question that I asked several tested developers, and so far I have not received a practically useful answer. However, the need for some additional input in the middle of processing is fairly common.
Thanks!
EDIT: this is application logic, so it clearly belongs to the model, and even if this is not the case, I would like to know a solution for cases where I really need user input in the middle of the business logic subroutine in the model.
wpf mvvm dialog synchronous model
Tomáš Kafka
source share