哨兵

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

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);
      }
    }
posted on 2015-04-29 09:05  哨兵  阅读(254)  评论(0编辑  收藏  举报