WPF MVVM – Where to Create a File in WPF/MVVM

cdesignmvvmnetwpf

I'm building a WPF/MVVM application that takes input from the user and generates an output document which it saves in a temporary folder and opens for display in the native application (e.g. MS Word). The document's data is, of course, represented by the model as well as the logic for constructing the actual document (including the interaction with a third-party library that works with document file formats).

My question is: should the actual file save-to-disk operation be in the model? Or should it pass some kind of object (stream, possibly) back to the view model so it can be saved to disk there. Where does something like that belong?

Best Answer

The Model is meant to represent both the current state of the data and the data access layer that represents the content. So, if you were using a database, you would handle read/write calls there. In that same vein, you should do disk reads and writes in your model (or, at least I would).

Related Topic