Duplicates a feature ?

Feb 28, 2012 at 3:03 PM
Recently discovered that MEF catalog allows the same type to appear multiple times 

e.g. the following code from prism/mef adds the parts multiple times ( i resolved it by manually doing duplicate checks)


AggregateCatalog
.Add( new AssemblyCatalog(Assembly1) )
 
AggregateCatalog.Add( new AssemblyCatalog(Assembly2) )
 
...

 
AggregateCatalog.Add( new DirectoryCatalog(".")  )



Question is - Is there a reason why MEF does not check for duplicates ? can't think of a reason why this would be a feature ?


Feb 28, 2012 at 4:44 PM

Hi Kumar,

We don’t have specific scenarios for this either, but didn’t want to prevent it. Sometimes, e.g. when adding instances to a composition, multiple instances of the same type (configured differently) can make sense. On top of this, duplicate checking would impact startup performance, which MEF is currently heavily optimized for.

Thanks for raising this though!

Nick

From: KumarNYC [email removed]
Sent: Tuesday, February 28, 2012 7:04 AM
To: Nicholas Blumhardt
Subject: Duplicates a feature ? [MEF:346568]

From: KumarNYC

Recently discovered that MEF catalog allows the same type to appear multiple times 

e.g. the following code from prism/mef adds the parts multiple times ( i resolved it by manually doing duplicate checks)


AggregateCatalog.Add( new AssemblyCatalog(Assembly1) )
AggregateCatalog.Add( new AssemblyCatalog(Assembly2) )
...

AggregateCatalog.Add( new DirectoryCatalog(".") )



Question is - Is there a reason why MEF does not check for duplicates ? can't think of a reason why this would be a feature ?