Ejemplo n.º 1
0
        /// <summary>
        /// By default, we are configured to use MEF
        /// </summary>
        protected override void Configure()
        {
            var catalog = new AggregateCatalog(
                AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>()
                );

            catalog.Catalogs.Add(new DirectoryCatalog(Environment.CurrentDirectory + "/AddIns"));

            container = new CompositionContainer(catalog);

            var batch = new CompositionBatch();

            var windowManager = new AvalonDockWindowManager();

            batch.AddExportedValue <IEventAggregator>(new EventAggregator());
            batch.AddExportedValue <IResourceService>(new ResourceService());
            batch.AddExportedValue <IWindowManager>(windowManager);
            batch.AddExportedValue <IDockWindowManager>(windowManager);
            batch.AddExportedValue <IConfigurationService>(new ConfigurationService(@"Configuration"));
            batch.AddExportedValue <IThemeService>(new ThemeService());
            batch.AddExportedValue <IOptionService>(new OptionService());
            batch.AddExportedValue(container);
            batch.AddExportedValue(catalog);

            container.Compose(batch);

            container.ComposeParts(container.GetExportedValue <IResourceService>());
            container.ComposeParts(container.GetExportedValue <IThemeService>());
            container.ComposeParts(container.GetExportedValue <IOptionService>());

            //Extend the name rule of ViewLocator, the rule is : LanguageOption -> LanaguageOptionView
            ViewLocator.NameTransformer.AddRule("Option$", "OptionView");
        }
        /// <summary>
        /// By default, we are configured to use MEF
        /// 配置相应的服务和程序集
        /// </summary>
        protected override void Configure()
        {
            //AggregateCatalog 向其基础目录添加的目录会自动重新组合
            //筛选加载的集合中的IEnumerable<ComposablePartCatalog>
            var catalog = new AggregateCatalog(
                AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>()
                );

            //AggregateCatalog 对象的基础目录中添加目录=》外部导入的dill或部件
            catalog.Catalogs.Add(new DirectoryCatalog(Environment.CurrentDirectory + "/AddIns"));

            container = new CompositionContainer(catalog);

            var batch = new CompositionBatch();

            var windowManager = new AvalonDockWindowManager();

            batch.AddExportedValue <IEventAggregator>(new EventAggregator());
            batch.AddExportedValue <IResourceService>(new ResourceService());
            batch.AddExportedValue <IWindowManager>(windowManager);
            batch.AddExportedValue <IDockWindowManager>(windowManager);
            batch.AddExportedValue <IConfigurationService>(new ConfigurationService(@"Configuration"));
            batch.AddExportedValue <IThemeService>(new ThemeService());
            batch.AddExportedValue <IOptionService>(new OptionService());
            ////疑惑-->下面2句有什么用?不加也正常运行
            //batch.AddExportedValue(container);
            //batch.AddExportedValue(catalog);

            container.Compose(batch);

            //ComposablePartCatalog aa=container.Catalog;
            //ReadOnlyCollection<ExportProvider> providers = container.Providers;

            container.ComposeParts(container.GetExportedValue <IResourceService>());
            container.ComposeParts(container.GetExportedValue <IThemeService>());
            container.ComposeParts(container.GetExportedValue <IOptionService>());

            //Extend the name rule of ViewLocator, the rule is : LanguageOption -> LanaguageOptionView
            ViewLocator.NameTransformer.AddRule("Option$", "OptionView");
        }