Ejemplo n.º 1
0
 public static CompositionContainer regisgter()
 {
     lock (obj)
     {
         try
         {
             if (_container != null)
             {
                 return(_container);
             }
             AggregateCatalog aggregateCatalog = new AggregateCatalog();
             string           path             = AppDomain.CurrentDomain.BaseDirectory;
             var thisAssembly = new DirectoryCatalog(path, "*.dll");
             if (thisAssembly.Count() == 0)
             {
                 path         = path + "bin\\";
                 thisAssembly = new DirectoryCatalog(path, "*.dll");
             }
             aggregateCatalog.Catalogs.Add(thisAssembly);
             _container = new CompositionContainer(aggregateCatalog, CompositionOptions.DisableSilentRejection);
             return(_container);
         }
         catch (Exception ex)
         {
             Console.WriteLine("错误:{0}", ex.Message);
             return(null);
         }
     }
 }
 public static CompositionContainer regisgter()
 {
     lock (obj)
     {
         try
         {
             if (_container != null)
             {
                 return(_container);
             }
             AggregateCatalog aggregateCatalog = new AggregateCatalog();
             string           path             = AppDomain.CurrentDomain.BaseDirectory;
             var thisAssembly = new DirectoryCatalog(path, "*.dll");
             if (thisAssembly.Count() == 0)
             {
                 path         = path + "bin\\";
                 thisAssembly = new DirectoryCatalog(path, "*.dll");
             }
             aggregateCatalog.Catalogs.Add(thisAssembly);
             _container = new CompositionContainer(aggregateCatalog);
             return(_container);
         }
         catch (Exception ex)
         {
             return(null);
         }
     }
 }
Ejemplo n.º 3
0
        public static void RegisterMef(HttpConfiguration config)
        {
            AggregateCatalog aggregateCatalog = new AggregateCatalog();
            string           path             = AppDomain.CurrentDomain.BaseDirectory;

            Console.WriteLine(path);
            var thisAssembly = new DirectoryCatalog(path, "*.dll");

            if (thisAssembly.Count() == 0)
            {
                path = path + "bin\\";
                Console.WriteLine(path);
                thisAssembly = new DirectoryCatalog(path, "*.dll");
            }
            aggregateCatalog.Catalogs.Add(thisAssembly);

            //DirectoryCatalog catalog = new DirectoryCatalog(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath);
            MefDependencySolver solver = new MefDependencySolver(aggregateCatalog);

            config.DependencyResolver = solver;
        }