Question

I have an application which use plugins. Each plugin is developped following MVVM, so I have a View, binded to a View-Model inside. like the following picture:

enter image description here

In my application I have a Designer, when I add any ViewModel in my ViewModels list, its view will appear in the Designer.

My question is: How can I keep this binding when adding the viewModel of my plugin in my list ?? how to make its view appear in my designer ?

Was it helpful?

Solution

This is an interesting question... and like always there are many ways to accomplish it.

It depends what your plugins are.

If the plugin is more integrated and not so isolated. You should think about some Factory classes which are for example named like ViewResolver or ViewModelResolver. They can take parameters like the name as string, a type, a type of an interface or work by conventions.

Purpose is to find the VM for a view and vice versa as a central service. This service should also locate plugin VM or import them for example with MEF.

For more info’s google on view-first, viewmodel-first, view viewmodel marriage, etc.

Or

If your plugins are fully fleshed out components which run independently. I would suggest your host application should have in its viewmodel a list of components which are the plugins. So the Model will be a Component no matter if it contains the view and everything else because of the hosting app is to manage the components. So you would have an ObservableCollection which are bound to content control. The content control can then host the plugin as a whole.

These are two possible ways... like I mentioned above there is no "the" way in mvvm and it always depends on your use cases... But I hope this guides you in the right direction...

HTH

OTHER TIPS

Thank you for the answer @Silverfighter! it made me things more clear !

I found a very intersting article wich seems adapted to my problem

The solution is here:

http://www.alphablog.org/2012/05/07/simple-plugin-system-based-on-ninject-and-mvvm-light-2/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top