This project is read-only.

Hooking into ViewModel creation

Sep 2, 2010 at 1:03 AM

Some context for this question is in MEF thread:

At the moment when ViewModel has to be resolved I would like the option to either:

a) do what library does now by default, i.e. resolves ViewModel instance via MEF

b) hand in already existing ViewModel object

I am looking for a suggestion on how/where in MEFedMVVM source code to do that in the best way possible. 

To put it simply, most of the time non_shared creation policy or new ViewModel instance for each new View instance is fine for me.

However, in some cases I need to reuse the existing ViewModel object because of the state that it holds.


Sep 2, 2010 at 6:59 AM

This is already possible. You can create what I call a DataContextAware ViewModel. Basically you can have the Export setup like this 

[ExportViewModel("MyVM", true)]

That true is telling MEFedMVVM that the ViewModel should not be created by MEF, but MEFedMVVM should still inject the services for the ViewModel (if you have any property imports i.e [Import]public IMyService Service{ get; set; } ). You can read more on this here