MEF and Prism, to be or not to be.

Now to the question, what is the story on Prism and MEF? I am getting asked this now several times a day, more so than the IoC question.

I am happy to say we’re working with p&p to come up with a good answer.

Note: This is still a work-in-progress, but here’s the thinking on this so far.

There is some obvious overlap but also a clear delineation. In particular when it comes to UI composition. MEF can be used for UI composition for sure, however it doesn’t have specific UI composition bits like RegionManager, Composite Commands, EventAggregator. Something like EventAgg will come in the future, but it is highly unlikely we will ever deliver some of the Prism UI-specific bits as part of MEF. That could change, but at least today that is the case.

In general though here are the differences.

  • First, MEF is in the platform as part of SL4/FX4.

  • Second, MEF is a general UI agnostic composition technology while Prism is specific for UI composition. MEF also extends beyond composite applications to general extensibility / plugin models.

  • Third, Prism and MEF can work together.

There are two primary use cases we hear from customers who want to use MEF and Prism together.

  1. Use Prism with MEF as an add-on for extensibility. That is make modules extensible through MEF.  You can think of this as the “Two worlds in harmony” solution. Your core architecture rests on Prism’s modularity / and an IoC Container and sits side by side with MEF.

  2. Use MEF primarily for modularity, and pull in Prism bits for UI composition.  In this model, your core architecutre sits on top of MEF, with MEF replacing the services of your IoC.

Note: You can also use MEF for some aspects of UI composition, particularly for pull-style regions which import their UI elements.

The first angle is primarily for customers who have existing applications that use Prism and want to use MEF. The second is for customers who are building new apps in SL4/FX4, that want to use MEF for providing the foundation, and pull in CAL libraries where appropriate.  I think both make equal sense depending on customer needs.

In terms of which to use when, my advice is it depends on your situation.

  • If you are already committed to Prism, stick with it. There will be guidance coming for integrating MEF and Prism in Prism 4.

  • If you are starting fresh (and you are choosing to use MEF) then you may to use MEF for modularity, and general aspects of your composite app and pull in Prism pieces where appropriate.

Comments (10)

  1. and of course, you can start fresh with MEF, and use some kind of light MVVM framework (or toolkit) to facilitate the composition 😉

  2. Of course…but where are my Regions? or my composite commands? 😉

  3. Leonardo says:

    Thanks for this post, now i can continue using prism and waiting for the guidance for integrating MEF and Prism.

    I can breath now 😉

  4. Mike Strobel says:

    Looking forward to Prism 3 and seeing some (hopefully thorough) examples of MEF integration.  I was a bit skeptical about MEF for the first couple releases, but it really seems to have matured nicely.  The fact that VS2010 is built around it goes a long way in demonstrating that it can work well even in the largest and most heavily extended applications.

  5. Alexey Zakharov says:

    Hi Glen,

    What is FX4 you have mentioned is in this post?

    Best regards,

    Alexey Zakharov.

  6. Jerry Merchand says:

    Glenn, I’m kind of new to the IoC, MEF, MAF, Unity and Prism way of building pluggable applicaitons.  I’m into trying to build a modular applicaiton w/ SL3/4 and would like to use Prism/MEF but it seem like this is very difficult to do easily.  Can p&p group / microsoft not create one solution for SL/WPF applications.  It seem to me like you guys are way off track compared to the Ruby Engine approach to building applications.

    Where is the whitepaper or book explaining these technologies in practical use?

    Thanks in advance for any light that can be shed! Jerry

  7. John says:

    Thanks Glen!  I’m new to this space.  Would you know where I can get a sample that demonstrates the use of Prism for UI composition and MEF for modularity.

  8. Hi John

    Best place I can point you to is the recent drops of Prism 4 which include a MEF modularity quickstart. Find it here:…/47253

  9. @Jerry

    I understand the confusion. Prism shipped while MEF was very early in development, too early for their to be a clean integration story. Howvevr, p&p is now very focused on providing a clean path for those who want to use MEF and Prism. Prism itself was designed in a decoupled fashion making this possible.

    Check out the link in my previous comment, and please post any feedback / concerns relating to the MEF integraiton on the Prism site.