Question

What is AggregateCatalog? What does it mean when you construct a new AggregateCatalog()? What does it mean when you add assemblies to the catalog, eg catalog.Catalogs.Add(new AssemblyCatalog(someAssembly))? Other than assemblies what can you add to the catalog? any general knowledge related to this would be helpful, too (I'm a total noob)

Was it helpful?

Solution

AggregateCatalog in MEF basically allows you to collect multiple extension catalogs. When you call new AggregateCatalog(), you are basically instantiating a new catalog collection (not necessarily populated) that can contain multiple instances of ComposablePartCatalog, which can contain multiple parts.

Consider it a class that helps you collect parts from multiple sets.

Assemblies are just a way to push parts to the calling application. You can pass parts directly from inside the existing assembly.

For more information about catalogs, I would recommend reading this.

OTHER TIPS

Mef has a small learning curve - go thru the docs at mef.codeplex.com atleast once. Or try screencasts if you're really pressed for time.

The idea is that a catalog is a dictionary of exported parts (objects to be injected) or parts that need imports (that need injected objects).. The catalog can be populated in multiple ways (hence the diff Catalog derivations) -- from a Directory (all asm in a dir) or a Specific assembly.

Next you can create a composite catalog e.g. you want to create a single dictionary that contains all exported objects from DirA and from this specific assembly lying in DirB. In this case, you can create individual catalogs and then a composite catalog which merges the two. Now you consume this merged dictionary in your code to ask for imports/exports.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top