using BuddyFinance.MEF.Contracts; using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; using System.Configuration; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace BuddyFinance.MEF { public class Importer { [ImportMany(typeof(ICreditBureauIntegrator))] public IEnumerable> _components; public Importer() { Import(); } public void Import() { //An aggregate catalog that combines multiple catalogs var catalog = new AggregateCatalog(); //Add all the parts found in all assemblies in //the same directory as the executing program catalog.Catalogs.Add(new DirectoryCatalog(Path.GetDirectoryName(ConfigurationManager.AppSettings["ComponentsFolder"]))); //Create the CompositionContainer with the parts in the catalog. CompositionContainer container = new CompositionContainer(catalog); //Fill the imports of this object container.ComposeParts(this); } } }