I specially liked the way you injected control into the StockModel [StockModel(symbol, IStockQuoteProvider)]

To be honest, I had some difficulty grasbing the why & how of the ActivateModel. I had to really think about it, but I think I get it now…with that said, would you please give an example of why you needed to do reference counting? In other words: For which scenarios the ActiviateModel you described isn’t good enough?

One example scenario where I needed ref counting in the activation was in Max when we had nested views where the inner view’s template was chosen programmatically based on the model state. Both the outer view and inner view needed to activate the model. If you don’t need this, no need to add the complexity.

Thanks for a post, it is very good. Currently I am working on creating a back end accounting application with WPF. Since we anticipate many calls to service layer (WCF), I liked the concept of DataModel. It was curious that the constructor of the viewModel DataModel is doing actual data extraction. I would have thought you will have separate GetData Method. Usually I try to perform minimal task in constructors.

I am also struggling about how to write an automated unit test for the PortfolioViewModel equivalent. To test the behavior of AddCommandModel and RemoveCommandModel etc. Any information you can provide in that domain can be helpful.

Actually the data extraction really happens when the model is activated.

To unit test AddCommandModel/RemoveCommandModel, you can set up some test data in PortfolioViewModel. Then, you can get the commands through the PropertyViewModel accessors and call OnQueryEnabled and OnExecute with different parameters to try it out. In cases where you need to get to private methods and data, use PrivateObject or PrivateType.

I tried to use your suggestion to call OnQueryEnabled and OnExecute directly. I keep getting error "The type CanExecuteRoutedEventArgs has no constructors defined". I am not able to find any sample which directly instantiates this class.

My aim is to create a console application to test the behavior of presenter. I guess if I create a windows based application I can use command binding and test this via Command object. But not sure how to do this in Console app.

Regarding multiple parameters for the CommandModel: what if we set the ViewModel as the parameter for the CommandModel. This way the CommandModel can be the link between the ViewModel and the DataModel and can validate against N number of values.