MEF: DirectoryPartCatalog

I am trying to write a simple MEF demo to find out about this. I am following this tutorial, but it seems to be out of date. The downloadable example works, but it uses the included assembly, which is 2 versions older (2008.9.4.0) than the current (4.0) that comes with Framwework 4.

In particular, it uses DirectoryPartCatalog, which I cannot find anywhere in the latest library. Can someone provide an example of how to detect pluggable assemblies from a directory with the current version of MEF?

thanks

+6
c # mef
source share
3 answers

You need to make a few changes so that this sample is compiled and run with the built-in version of System.ComponentModel.Composition.

class Program { [ImportMany] // [Import] public IEnumerable<string> Messages { get; set; } [ImportMany] // [Import] public IEnumerable<IOutputString> OutputSet { get; set; } [Import("OutputMessages")] public Action<IEnumerable<IOutputString>, IEnumerable<string>> OutputMessages { get; set; } public void Run() { var catalog = new AggregateCatalog(); // AggregatingComposablePartCatalog catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\..\ExternalMessages\bin\Debug")); // DirectoryPartCatalog catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\..\ExtraMessages")); // DirectoryPartCatalog catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); // AttributedAssemblyPartCatalog var container = new CompositionContainer(catalog); // CompositionContainer(catalog.CreateResolver()); // container.AddPart(this); // container.Compose(); container.ComposeParts(this); OutputMessages(OutputSet, Messages); } static void Main(string[] args) { Program p = new Program(); p.Run(); } } 
+6
source share

DirectoryPartCatalog is now called DirectoryCatalog

+2
source share

I think you are looking for DirectoryCatalog

+2
source share

All Articles