XAP Partitioning and the PRISM RegionManager

May 17, 2010 at 7:50 PM

You guys probably get questions about PRISM and MEF all the time.  Sorry to ask another one.  I was wondering if you could point me in the right direction on this question.  Really I'm kind of wondering if these pieces of PRISM are still worth using when using MEF with partitioned XAPs. 

Can I still use the RegionManager and IModule pattern with partitioned XAPs that support recomposition?  Removing views already registered with the region manager seems to be an issue (if that view is being recomposed).  Also the strong references required in the GetModuleCatalog function for the IModule pattern to work seems to be an issue.

I've thought about MEFizing the IModule interface into an InheritedExport and managing that through a recomposable collection.  This would be in the code I'm using to add and remove DeploymentCatalogs from my AggregateCatalog.  However, this seems like overkill.  Is it worth it?  Is there an altered pattern I could use with MEF to still be able to manage my regions effectively?

Thanks,

-Nick 

May 17, 2010 at 8:40 PM

Hi Nick

p&p is looking to leverage MEF fully as part of Prism 4. MEF and Prism definitely can be used together.

The key areas where MEF plays in are:

1. Modularity - MEF provides a great mechansim for partitioning your applications into modules. A part basically is a module in MEF terms in the sense that it is dynamically discovered similar to IModule in Prism. This offers more flexibility from a modular perspective than today is offered in Prism.

2. Composite UI - MEF has an interesting angle for doing some aspects of UI Composition. You can for example use metadata in MEF for designating which parts of the UI a particular component belongs to, and then have a manager which pulls in all the pieces and composes them.

You can read more about the Prism / MEF direction on this post: http://blogs.msdn.com/dphill/archive/2009/12/09/prism-and-mef.aspx

As far as meshing existing Prism bits with MEF today, it can fairly easily be done. Two approaches that seem to be quite common are pulling the RegionManger, EventAggregator and commanding into MEF. You can easily derive from the RegionManager or EventAggegator and add exports in order to put them into MEF's container. This will allow you to leverage Prism's composite UI mechanisms as well as cross part communication services.

You can also roll your own module loading mechanism with MEF. For example here is a simple snippet that shows how one could load modules: http://codepaste.net/ntot6w

Keep watch on the p&p site / David Hill's blog as you are sure to see MEF/Prism stuff coming soon.

Thanks

Glenn

May 17, 2010 at 9:28 PM

Great, I'll dig into this info.  Off hand do you know if MEF holds references to objects with a property marked as ImportMany(AllowRecomposition:=true) or one implementing IPartImportsSatisfiedNotification?  Is it possible for me to remove this reference somehow?  My object needs to be released so it doesn't get recomposed.  I'm having a lot of trouble trying to figure this one out.

Thanks,

-Nick