你的位置:首页 > ASP.net教程

[ASP.net教程]MEF example code


 

public interface IObjectResolver  {  }public class ObjectResolver:IObjectResolver  {   private CompositionContainer container;   public ObjectResolver()   {     container = new CompositionContainer(new AggregateCatalog());   }   public void AddCatalogFile(string fileName)   {     if (!File.Exists(fileName))       throw new FileNotFoundException();     AggregateCatalog catalog = (AggregateCatalog)container.Catalog;     catalog.Catalogs.Add(new AssemblyCatalog(fileName));     container.ComposeParts();   }   public T GetExport<T>(string name)   {     return container.GetExportedValue<T>(name);   }  }