Hi!

I am developing a WPF-application with the MVVM-pattern (no code behind). Yesterday I had a discussion with a colleague on where to load some initial data. Our viewmodel has a "PopulateList()"method that loads some data from the repository into an ObservableCollection property. We initialize every viewmodel and other dependencies in an IoC container (unity) But where to call PopulateList()? Basically, we have two choices:

1) Call it in the viewmodel constructor
2) Use a behaviour and hook up to the "onload" and bind the behaviour to a command, and execute the command (which points to the PopulateList Action)

We have done it with a call in the construvot, but I see some problems with this

1) Performance, if I have multiple viewmodels (say 20) and every one of them does some loading of stuff to their views, I want to use async/await. But that is not allowed in a constructor as far as I know for various reasons...

2) Testability. I like to unit test my viewmodels, and having an external call in the constructor seems like a hazzle. I do want unit tests for "first load" scenarios, to make sure everything is hooked up properly (commands, properties etc), but I want to mock it. If I use behaviours, how can I then verify that the "repository.GetINitialData" was called or not, since the viewmodel command for this is executed only when the view is loaded? It is easier if I put it in the constructor... but somehow it doens't feel right to do async data loading in the constructor (async, ioc issues)

Your thoughts?

/H