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); } } }
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; }