views:

23

answers:

2

I am building a tool which goal is to download a file based on a few parameters.

First step is to set (or retrieve) those parameters.

The different parameters sets are retrieved (let's say via configuration files) by a FileDownloadsManager : it knows exactly which parameters to use in order to download the right file.

those parameters are stored in a class, and I have a list of instances of this class.

That means that I can download my file with multiple possible parameters sets.

Around those ParameterSets, I've built ParametersSetsViewModels so that I can display them in a list, and add some View-Only properties. Internally, the ParametersSetsViewModels have a reference to the underlying ParametersSets used as a source for the members of the View Model.

now, when I select my parameters set, I would like the related file to be downloaded.

Whose responsibility should this be ?

I have this feeling that if the ViewModel is too active, by having a method that returns the downloaded file, this would be against the MVVM pattern; what is your take on this ?

Bonus : the download should be feasible in the background with BackgroundWorkers or WebClient's asynchronous methods.

A: 

Though I am not quite sure whether I got everything right regarding your architecture, I would do the following.

I agree that the ViewModel should not doing the download and return the file. The ViewModel should start the download by calling a service that is doing the download. Maybe your FileDownloadsManager can be such a service. Having such a service has the advantage that you can do the work in a separate thread very easily.

This is what I would do! I am sure are different ways of achieving your goal.

regards, Florian

Florian
I think that both of you, HiTech Magic and yourself got it right. the "service" approach ( or Controller as HiTech Magic calls it ) is definitely the way to go.
Salfab
A: 
Enough already
Thank you for your insight, especially for the reflection on "MVCVM" : this is definitely something worth being said : Controlers are still alive !
Salfab