Ejemplo n.º 1
0
        /// <summary>
        /// Wczytuje wszystkie moduły aplikacji.
        /// </summary>
        /// <returns>True - jeśli powiodło się wczytywanie</returns>
        private bool Compose()
        {
            IDictionary <string, IList <string> > dllFiles = null;

            try
            {
                dllFiles = PluginChecker.Instance.ReadAndCheckPlugins();
            }
            catch (InvalidPluginException ex)
            {
                LogException(ex, ex.Message);
                return(false);
            }

            var exportFactoryProvider = new ExportFactoryProvider();

            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new DllDirectoryCatalog(PluginChecker.LIB_DIR, dllFiles[PluginChecker.LIB_DIR]));
            catalog.Catalogs.Add(new DllDirectoryCatalog(PluginChecker.EXT_DIR, dllFiles[PluginChecker.EXT_DIR]));

            _container = new CompositionContainer(catalog, exportFactoryProvider);
            exportFactoryProvider.SourceProvider = _container;

            try
            {
                _container.ComposeParts(this);
            }
            catch (Exception ex)
            {
                LogException(ex, "Application startup error. See logs.");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void SetupMultipleFactories()
        {
            var catalog = new TypeCatalog(typeof(PartA), typeof(PartB), typeof(PartThatUsesACollectionOfFactories));
            var ep      = new ExportFactoryProvider();

            _container        = new CompositionContainer(catalog, ep);
            ep.SourceProvider = _container;
        }
Ejemplo n.º 3
0
        public void SetupSingleFactory()
        {
            var catalog = new TypeCatalog(typeof(PartA), typeof(PartThatUsesAFactory));
            var ep      = new ExportFactoryProvider();

            _container        = new CompositionContainer(catalog, ep);
            ep.SourceProvider = _container;
        }
Ejemplo n.º 4
0
        protected override CompositionContainer CreateContainer()
        {
            var exportFactoryProvider = new ExportFactoryProvider();
            var container             = new CompositionContainer(this.AggregateCatalog, exportFactoryProvider);

            exportFactoryProvider.SourceProvider = container;
            return(container);
        }
Ejemplo n.º 5
0
        public MEFViewModelResolver()
        {
            var catalog   = new AssemblyCatalog(GetType().Assembly);
            var ep        = new ExportFactoryProvider();
            var container = new CompositionContainer(catalog, ep);

            ep.SourceProvider = container;
            container.SatisfyImportsOnce(this);
        }
Ejemplo n.º 6
0
        protected override CompositionContainer CreateContainer()
        {
            var exportFactoryProvider = new ExportFactoryProvider();
            var container             = new CompositionContainer(this.AggregateCatalog, exportFactoryProvider);

            exportFactoryProvider.SourceProvider = container;

            return(container);

            //var debugger = new MefDebugger(container);
            //container.ComposeParts(this);
            //debugger.Close();
        }
Ejemplo n.º 7
0
        //[MTAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
            var exportFactoryProvider = new ExportFactoryProvider(); // enable use of ExportFactory
            var container             = new CompositionContainer(catalog, exportFactoryProvider);

            exportFactoryProvider.SourceProvider = container; // enable use of ExportFactory
            var mainForm = container.GetExportedValue <MainForm>();

            Application.Run(mainForm);
        }