0
votes

I am learning the Prism framework and how MEF is integrated with it... I am looking at the "StockTraderRI" demo solution that comes with Prism as an example...

When the [EXPORT] attribute is used on a viewmodel such as this: [Export(typeof(TrendLineViewModel))]

Does MEF create a list of these in one of its internal structures so that when it is imported like this: [Import] TrendLineViewModel ViewModel it can be located?

The it looks like the exporting of views is doing something similar: [ViewExport(RegionName = RegionNames.ResearchRegion)]

which is then used in the AutoPopulateExportedViewsBehavior method to inject the views in the regions.. is this correct?

Thanks Harold

1

1 Answers

1
votes

When you put "attributes" (the square bracket things) on types, you are attaching "metadata" to that type that can be discovered at runtime by using reflection.

When you configure MEF you give it a Catalog which tells it which assemblies it should scan for the [Import] and [Export] metadata attributes. For example a DirectoryCatalog will get MEF to scan a set of assemblies/DLLs in a particular directory.

When you ask for a type to be created/composed, it knows how to resolve the creation of that part i.e. it matches up [Import] and [Export]s which are of the same contract.