コード例 #1
0
ファイル: MEFLoader.cs プロジェクト: CobyC/JaRS
        /// <summary>
        /// This Method allows for additional catalogs to be added to the main MEF catalog.
        /// This is so that the Client application can have other classes/plugins that needs to be instantiated by MEF.
        /// </summary>
        /// <param name="catalogParts"></param>
        /// <returns></returns>
        public static CompositionContainer Init(ICollection <ComposablePartCatalog> catalogParts)
        {
            AggregateCatalog catalog = new AggregateCatalog();

            RegistrationBuilder pluginBuilder = new RegistrationBuilder();

            pluginBuilder.ForTypesDerivedFrom <IPluginWinForms>()
            .Export()
            .ExportInterfaces();

            foreach (var assembly in AssemblyLoaderUtil.WinFormsPlugins)
            {
                AssemblyCatalog assemCatalog = new AssemblyCatalog(assembly, pluginBuilder);
                assemCatalog.FixCatalogForRegistrationBuilderBug();
                catalogParts.Add(assemCatalog);
            }
            //The plugin factory assembly
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(PluginFactory).Assembly));

            if (catalogParts != null)
            {
                foreach (var part in catalogParts)
                {
                    catalog.Catalogs.Add(part);
                }
            }

            CompositionContainer container = new CompositionContainer(catalog);

            return(container);
        }
コード例 #2
0
        /// <summary>
        /// This Method allows for additional catalogs to be added to the main MEF catalog.
        /// This is so that the Client application can have other classes/plugins that needs to be instantiated by MEF.
        /// </summary>
        /// <param name="catalogParts"></param>
        /// <returns>returns the filled composition container</returns>
        public static CompositionContainer Init(ICollection <ComposablePartCatalog> catalogParts)
        {
            AggregateCatalog catalog = new AggregateCatalog();

            if (catalogParts == null)
            {
                catalogParts = new List <ComposablePartCatalog>();
            }


            RegistrationBuilder dataBuilder = new RegistrationBuilder();

            dataBuilder
            .ForTypesDerivedFrom <IDataContextBase>()
            .Export()
            .ExportInterfaces();
            dataBuilder
            .ForTypesDerivedFrom <IDataRepositoryBase>()
            .Export()
            .ExportInterfaces();

            if (ConfigurationManager.AppSettings["UseWebPath"].ToLower() == "true")
            {
                AssemblyCatalog assemCat1 = new AssemblyCatalog(typeof(DataRepositoryFactory).Assembly, dataBuilder);
                assemCat1.FixCatalogForRegistrationBuilderBug();
                catalog.Catalogs.Add(assemCat1);

                /* this worked..
                 * AssemblyCatalog assemCat2 = new AssemblyCatalog(typeof(ApptLabelRepository).Assembly, dataBuilder);
                 * assemCat2.FixCatalogForRegistrationBuilderBug();
                 * catalog.Catalogs.Add(assemCat2);
                 */
                var catDir = new DirectoryCatalog(AssemblyLoaderUtil._executingDirectory, "*.data.*");
                catDir.FixCatalogForRegistrationBuilderBug();
                catalog.Catalogs.Add(catDir);
            }
            else
            {
                AssemblyCatalog assemCat1 = new AssemblyCatalog(typeof(DataRepositoryFactory).Assembly, dataBuilder);
                assemCat1.FixCatalogForRegistrationBuilderBug();
                catalog.Catalogs.Add(assemCat1);

                foreach (var assem in AssemblyLoaderUtil.DataAssemblies)
                {
                    AssemblyCatalog assemCat = new AssemblyCatalog(assem, dataBuilder);
                    assemCat.FixCatalogForRegistrationBuilderBug();
                    catalogParts.Add(assemCat);
                }
            }

            //add items to catalog here
            //we only have to give in any one of the classes in the assembly that we want to load,
            // it will automatically look for any other classes down the chain, marked as 'Export' in that assembly.

            if (catalogParts != null)
            {
                foreach (var part in catalogParts)
                {
                    catalog.Catalogs.Add(part);
                }
            }

            CompositionContainer container = new CompositionContainer(catalog);

            return(container);
        }