Esempio n. 1
0
        /// <summary>
        /// 初始化MEF容器
        /// </summary>
        /// <param name="subDirName">dll目录名称</param>
        public static AppStartup InitMEF(this AppStartup startup, string subDirName = "")
        {
            var catalog = new AggregateCatalog();

            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, subDirName ?? string.Empty);

            if (!Directory.Exists(path))
            {
                throw new ArgumentException("初始化MEF目录未找到");
            }

            catalog.Catalogs.Add(new DirectoryCatalog(path));

            var container = new CompositionContainer(catalog, true);

            EasyMefContainer.InitMefContainer(container);

            return(startup);
        }
Esempio n. 2
0
        /// <summary>
        /// 初始化MEF容器
        /// </summary>
        public static AppStartup InitMEF(this AppStartup startup, params Type[] typeList)
        {
            if (typeList == null || typeList.Length <= 0)
            {
                return(startup);
            }

            var typeDistinctList = typeList.Distinct();

            var catalog = new AggregateCatalog();

            foreach (var type in typeDistinctList)
            {
                catalog.Catalogs.Add(new TypeCatalog(type));
            }

            var container = new CompositionContainer(catalog, true);

            EasyMefContainer.InitMefContainer(container);

            return(startup);
        }
Esempio n. 3
0
        /// <summary>
        /// 初始化MEF容器
        /// </summary>
        public static AppStartup InitMEF(this AppStartup startup, params Assembly[] assemblyList)
        {
            if (assemblyList == null || assemblyList.Length <= 0)
            {
                return(startup);
            }

            var assemblyDistinctList = assemblyList.Distinct();

            var catalog = new AggregateCatalog();

            foreach (var assembly in assemblyDistinctList)
            {
                catalog.Catalogs.Add(new AssemblyCatalog(assembly));
            }

            var container = new CompositionContainer(catalog, true);

            EasyMefContainer.InitMefContainer(container);

            return(startup);
        }