OpenLightGroup Blog


Blogs from

My MEF Rant

This is my MEF rant. Let me say up front that I do not think that Microsoft is doing anything incorrectly. But I have had a chance to spend at least 10 hours working with MEF so I now feel that I am educated enough about it to post a good old fashion rant.

What Is MEF?

The documentation for The Managed Extensibility Framework (MEF) describes its purpose as a tool that "...simplifies the creation of extensible applications". That is a very general statement. It's like describing nuclear physics as "the field of physics that studies the building blocks and interactions of atomic nuclei". In some ways MEF is as powerful to programming as nuclear physics is to science.




I wrote an article that describes how you can use it to dynamically load a .xap file:


Mef = Good? or Why Should You Want To Use It?


I have a article that I am working on that allows you to use MEF to dynamically load different versions of a Video Player. The main project is in a file called SkinableVideoPlayer.xap and it is the first project to load.

It uses MEF to load the custom video players that are contained in .xaps.




When you normally build the project the .xap size for the custom video player is about 466 kb.




We can change the name of the .xap file to .zip, and open it up, we see that the only file we really need, is the customized player that is is only 6 kb.

All the other files are assemblies that are referenced by the custom video player.




First we make sure that the main project, SkinableVideoPlayer, has a reference to all the assemblies that we will need, then we go to references in the custom video player, and set all of them to Copy Local = False.



Now, when we build the size of the .xap is only 6 kb!


Ok sign me up and give me a T-Shirt, and a membership card, to the I LOVE MEF! fan club. I’m sold.

With a Silverlight application, reducing the file size and dynamically loading components only when needed is a very BIG DEAL.

Note: Please understand that MEF can only work this “magic” if the required assemblies are loaded (Copy Local is set to True) by another .xap before it is needed. In my case this .xap is the SkinableVideoPlayer.xap, and as you can see in the screen shots above, it is still a hefty 488kb because it DOES contain the assemblies.

My point is that without MEF I was forced to load the SkinableVideoPlayer.xap at 488 kb AND the Hiro.xap for an additional 466 kb. In my article I plan to have about 4 players and it would be a 488 kb hit each time. Using MEF I only need to load 24 kb for all 4 players rather than 2330 kb. Unless my math is wrong that is a 97% reduction.


What Is Missing?

Once you understand MEF it’s not that hard, but it STAYS complicated. It is very powerful and anything powerful is inherently complex. However, anything complex can be simplified.

It should not take hundreds of words and dozens of screen shots to explain how to dynamically load a .xap file. This reminds me of the time when web services were first introduced. you had to create your web proxys manually. That has now been replaced by a simple “Add Web Reference” in Visual Studio.


What I Want To See

It is standard procedure for Microsoft to release something in it’s most basic form, then progressively enhance it according to customer feedback. MEF is in the middle of that process. Things are progressing according to plan.

Well here is some “Customer Feedback” :)

So what I want Microsoft to add, is something like this:


1) The ability to right-click in Visual Studio to set a "MEF Reference" that will automatically note the assemblies in the project that I am adding and set them to copy Local=False if the parent project already has them
2) Then it shows me the referenced projects in a window and I can drag and drop them directly onto the Design surface and it will automatically write all the code.
3) I can also interact with it in code behind.

Basically give me the same experience I have with web services :)

Comments are closed.
Showing 4 Comments
Avatar  Michael Washington 8 years ago

@Michaud Venant - My point was "It should not be so hard to simply load a .xap!". I thought that qualified as a "Rant". But, your point is still well taken, I agree it came off more as a 'MEF love fest' :)

Avatar  Michaud Venant 8 years ago

This is not actually a Rant. More of a first impression and a suggestion... :)

Avatar  Michael Washington 8 years ago

@Fallon - Thanks for the feedback. I am sure if this idea is implemented, it will be different than the way I have detailed it. Microsoft pays a lot of bright people a lot of money to properly figure this stuff out :)

Avatar  Fallon 8 years ago

I'm not sure if the way you're asking them to implement the feature is the best way, but I'm sure that you've got a good suggestion here.<br><br>I do this a lot, and sometimes I get lazy about dependencies, and just allow the xap to be a bit larger than it needs to be.<br><br>A little help like this would be greatly appreciated.<br><br>Good point!