I use prism/mvvm/mef for my app, and loading all Views marked with ViewExport(Region) does work nicely (I’m using the StockTraderRI AutoPopulateExportedViewsBehaviour).
Now I’d like to use this runtime lookup capability to initialise some other background classes.
Say I got an interface
public interface ITable
{
}
And I got a lot of classes deriving from this interface.
Is there a way to mark those derived classes somehow and get MEF to create them on runtime and add them into some kind of list or container?
Like into a region which is not shown anywhere, I’d expect? How would I achieve this in MEF?
Sure there is!
Mark the classes inheriting your interface with Export attribute and in another class create yourself a property say of generic type ObservableCollection with attribute [ImportMany]. The should do the trick.