MEF vs. System.AddIn?

Nov 20, 2008 at 6:14 AM
Edited Dec 1, 2008 at 1:03 AM
Hi there,

I don't get it. I haven't done anything with MEF yet, basically I just read through a bit of information and watched the PDC session on MEF. When the System.AddIn namespace was announced and released a while ago I read about this and thought that this is the way extensibility will be supported (and should be implemented) in the future. Is MEF a replacement to  System.AddIn? One thing I was impressed by, in the System.AddIn namespace, is that it seems to address versioning issues between hosts and plugins where for example the host (v2) can support v1 plugins and where a v2 plugin can run on a v1 host... Can MEF do the same?

Any clarification appreciated.
Dec 1, 2008 at 1:04 AM
anyone?
Dec 1, 2008 at 1:52 AM

In terms of your specific question, MEF does have some versioning support in that contracts are just strings rather than hard references. Combining this with our contract adapter support means you can have an app that imports a V2 version of a contract, yet the exporter is a V1. The contract adapter will allow you to wrap the V1 so it looks like a V2. To the app it will be transparent.

As far as the general differences between MEF and MAF, they both focus on two different sets of problems.

System.Addin is a great technology for addressing issues around versioning resliance, isolation and recoverability.
• Using System.Addin allows you to host different components in separate app domains, thus allowing those addins to have different versions of assemblies which they reference which all run in the same process.
• System.Addin allows you to separately version Addins so that you could have two versions of an Addin sitting side by side.
• System.Addin manages automatically unloading app-domains they are no longer used thus allowing you reclaim memory.
• System.Addin has a bunch of security infrastructure (addins run in a sandbox) to ensure that components that are loaded do not have unauthorized access to data in the rest of the app.
• System.AddIn allows your app to gracefully recover whenever one of the addins crashes (this is due to isolation)

MEF on the other hand is a great technology for discovery and composition
• MEF composes deep object hierarchies of components
• MEF abstracts components from static dependencies.
• MEF can allow components to be lazily loaded and lazily instantiated.
• MEF provides a cataloging mechanism and rich metadata for components to allow them to dynamically discovered.
• MEF can compose components from various programming models, it is not bound to static types.

There is some overlap, in that System.Addin can do some discovery through its token mechanism, and MEF can do some versioning due to its loosely coupled  dependency mechanism and contract adapters. However the support is minimal compared to the specialization of each of the technologies.

As far as the long term perspective, MEF is being position as the framework for extensibility going forward.

Hope this helps.
Glenn

Dec 1, 2008 at 3:51 PM
Should we understand that eventually MEF will integrate/use System.Addin under the cover and so, will also have its benefits ? Versioning, isolation, recoverability and security are all vital components of an extensibility framework IMHO and it would be sad to have to choose between those and the great API that MEF provides.
Dec 1, 2008 at 4:12 PM
Edited Dec 1, 2008 at 4:15 PM
Hi Slorion

I undestand your concern. In the short term we are planning to give some guidance (probably some samples) on how MEF and MAF can work together. In our vNext we will be looking into either a tighter integration story, or bringing in covering those scenarios within MEF. This is investigative work we need to do, and we can't commit.

If you think this is an important area for us to cover, please create a work item so others can vote.

Thanks for the feedback.
Glenn
Dec 1, 2008 at 5:41 PM

Done @ http://www.codeplex.com/MEF/WorkItem/View.aspx?WorkItemId=6688

Thanks for your quick reply,

Sébastien

Dec 2, 2008 at 12:21 AM
Hi Glenn,

Thank you for your reply. Helps a lot.

Patrick
Dec 2, 2008 at 8:42 AM
Hi Glenn,

I would like to ask you if MEF supports unloading of modules.
Also do you know of a  more complex example with MEF ? Something like Navision (the first thing that comes to my mind) where you have modules which are loaded when requested and affect the UI.
Thanks,
Kiril

Dec 2, 2008 at 8:56 AM

Hi Kiril

MEF by itself does not. MAF (System.Addin) does. MEF with MAF would allow you to do that. I’m planning a sample to illustrate how this will work.

In terms of samples with dynamic module loading, we don’t really have anything as of yet. We’re going to be doing some work though with p&p to put together a sample of the Prism (www.microsoft.com/compositewpf) Stock Trader app (which is a modular app) which will build on top of MEF.

Thanks

Glenn

From: KirilRusev [mailto:notifications@codeplex.com]
Sent: Tuesday, December 02, 2008 12:43 AM
To: Glenn Block
Subject: Re: MEF vs. System.AddIn? [MEF:40335]

From: KirilRusev

Hi Glenn,

I would like to ask you if MEF supports unloading of modules.
Also do you know of a more complex example with MEF ? Something like Navision (the first thing that comes to my mind) where you have modules which are loaded when requested and affect the UI.
Thanks,
Kiril

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 2, 2008 at 12:53 PM
Edited Dec 2, 2008 at 12:53 PM
Hi Glenn,
Thank you for your quick response!

The Stock Trader app is just what i need. The small difference is that I also need a the same modular architecture in Silverlight/ASP.net.
As far as I understand there are currently four Extensibility frameworks in.NET
1) MEF
2) System.Addin
3)Enterprise Library Unity Application Block 
4) Prism (www.microsoft.com/compositewpf)

Right now I am confused about them and in what way they differ from each other. Is there any paper/article about that?
I also would like to know what is the difference in terms of application speed, loading times and memory between them.

Regards,
Kiril

Dec 2, 2008 at 6:14 PM
Hi Kiril

Prism is currently being developed for Silverlight. MEF also will be supported in Silverlight though the verdict is still out on whether or not it will ship in the box or be a separate download.

Glenn
Dec 4, 2008 at 6:41 AM
Hi Glenn,

Could you provide me with an roadmap? For example, when do you plan to move to beta and when do you expect to be in a final version.

Thanks,
Kiril
Dec 12, 2008 at 2:04 AM
So creating an application using MEF, MAF and CompositeWPF is something that you guys would recommend? I would love to see a sample project where MAF is used alongside MEF. That would be extremely helpful.
Dec 12, 2008 at 3:40 AM
I just wanted to add to the noise, not really providing value/answer, but mount the pressure/need for a simple sample integrating all the following together:

Prism, MEF & MAF
May 8, 2009 at 9:01 PM

Just curious if anything is happening on the Prism+MEF+MAF sample?

I'm really anxious to see that, and it sounds like several others are too.

Thanks!

Jun 12, 2009 at 5:32 AM

@Glenn
Any update on the MAF+MEF sample you had refered to?

Is there anyone who has experience with the Prism+MEF+MAF system?

Oct 27, 2010 at 1:38 PM

Yes...is there any progress on MEF+MAF (unloading of MEF addins is what i'm interested in)

Oct 27, 2010 at 1:46 PM
Edited Oct 27, 2010 at 1:47 PM

Don't know much about MAF (from my non-user perspective I just gave up, seemed too complicated!) but I know MEF better!

About MEF, maybe you would like to read the life time policy and sharing policy of MEF instances?
http://mef.codeplex.com/wikipage?title=Parts%20Lifetime&referringTitle=Guide

also of interest
http://mef.codeplex.com/wikipage?title=Recomposition&referringTitle=Guide