当前位置: 首页>>代码示例>>C#>>正文


C# CompositionContainer.Compose方法代码示例

本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionContainer.Compose方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionContainer.Compose方法的具体用法?C# CompositionContainer.Compose怎么用?C# CompositionContainer.Compose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.Composition.Hosting.CompositionContainer的用法示例。


在下文中一共展示了CompositionContainer.Compose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnStartup

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            #if (DEBUG != true)
            // Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't
            // jump into the code when an exception occurs.
            DispatcherUnhandledException += AppDispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
            #endif
            XmlConfigurator.Configure();
            _log.Debug("OnStartup called");

            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(IApplicationController).Assembly));
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ValidationModel).Assembly));

            _container = new CompositionContainer(catalog);
            var batch = new CompositionBatch();
            batch.AddExportedValue(_container);
            _container.Compose(batch);

            _controller = _container.GetExportedValue<IApplicationController>();
            _controller.Initialize();
            _controller.Run();
        }
开发者ID:nootn,项目名称:ClinImIm,代码行数:28,代码来源:App.xaml.cs

示例2: Compose

        private bool Compose()
        {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            //catalog.Catalogs.Add(new AssemblyCatalog(typeof(IEmailService).Assembly));

            _container = new CompositionContainer(catalog);
            var batch = new CompositionBatch();
            batch.AddPart(this);

            #if DEBUG
            _container.Compose(batch);
            #else
            try
            {
                _container.Compose(batch);
            }
            catch (CompositionException compositionException)
            {
                MessageBox.Show(compositionException.ToString());
                Shutdown(1);
                return false;
            }
            #endif
            return true;
        }
开发者ID:Dazmo,项目名称:Terraria-Map-Editor,代码行数:26,代码来源:App.xaml.cs

示例3: Configure

		protected override void Configure()
		{
			_container = new CompositionContainer(new AggregateCatalog(AssemblySource
					.Instance
					.Select(x => new AssemblyCatalog(x))
					.OfType<ComposablePartCatalog>()
				)
			);

			var batch = new CompositionBatch();
			
			_portName = SerialPort.GetPortNames()[0];
			_ecr = new Dp25(_portName);

			var messenger = new MessageAggregator();

			messenger.GetStream<SelectedPortChangedEvent>()
					.Subscribe(e => _ecr.ChangePort(e.PortName));



			batch.AddExportedValue<IWindowManager>(new WindowManager());
			batch.AddExportedValue<IMessageAggregator>(messenger);
			batch.AddExportedValue<Dp25>(_ecr);
			batch.AddExportedValue(_container);

			_container.Compose(batch);
		}
开发者ID:BurnOutDev,项目名称:Kasa.ge,代码行数:28,代码来源:AppBootstrapper.cs

示例4: ComposeWithTypesExportedFromPythonAndCSharp

        public void ComposeWithTypesExportedFromPythonAndCSharp(
            object compositionTarget,
            string scriptsToImport,
            params Type[] typesToImport)
        {
            ScriptSource script;
            var engine = Python.CreateEngine();
            using (var scriptStream = GetType().Assembly.
                GetManifestResourceStream(GetType(), scriptsToImport))
            using (var scriptText = new StreamReader(scriptStream))
            {
                script = engine.CreateScriptSourceFromString(scriptText.ReadToEnd());
            }

            var typeExtractor = new ExtractTypesFromScript(engine);
            var exports = typeExtractor.GetPartsFromScript(script, typesToImport).ToList();

            var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            var container = new CompositionContainer(catalog);
            var batch = new CompositionBatch(exports, new ComposablePart[] { });
            container.Compose(batch);

            container.SatisfyImportsOnce(compositionTarget);
        }
开发者ID:orthros,项目名称:IronPythonMef,代码行数:25,代码来源:CompositionHelper.cs

示例5: GetMefContainer

        public static CompositionContainer GetMefContainer(string binDirPath, CompositionBatch batch = null, RegistrationBuilder builder = null)
        {
            if (builder == null)
                builder = new RegistrationBuilder();

            builder.ForTypesDerivedFrom<Controller>()
                            .SetCreationPolicy(CreationPolicy.NonShared).Export();

            builder.ForTypesDerivedFrom<ApiController>()
                .SetCreationPolicy(CreationPolicy.NonShared).Export();

            var catalogs = new DirectoryCatalog(binDirPath, builder);

            var container = new CompositionContainer(catalogs, CompositionOptions.DisableSilentRejection |
                                                               CompositionOptions.IsThreadSafe);

            if (batch == null)
                batch = new CompositionBatch();

            // make container availalbe for di
            batch.AddExportedValue(container);

            container.Compose(batch);

            return container;
        }
开发者ID:Hem,项目名称:SimpleNet,代码行数:26,代码来源:MefRegistrationForMvcWebApi.cs

示例6: OnStartup

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            DispatcherUnhandledException += AppDispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;

            catalog = new AggregateCatalog();
            // Add the WpfApplicationFramework assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMessageService).Assembly));
            
            // Load module assemblies as well. See App.config file.
            foreach (string moduleAssembly in Settings.Default.ModuleAssemblies)
            {
                catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly));
            }

            container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);
            CompositionBatch batch = new CompositionBatch();
            batch.AddExportedValue(container);
            container.Compose(batch);

            // Initialize all presentation services
            var presentationServices = container.GetExportedValues<IPresentationService>();
            foreach (var presentationService in presentationServices) { presentationService.Initialize(); }
            
            // Initialize and run all module controllers
            moduleControllers = container.GetExportedValues<IModuleController>();
            foreach (var moduleController in moduleControllers) { moduleController.Initialize(); }
            foreach (var moduleController in moduleControllers) { moduleController.Run(); }
        }
开发者ID:jbe2277,项目名称:waf,代码行数:31,代码来源:App.xaml.cs

示例7: Configure

        protected override void Configure()
        {
            _container = new CompositionContainer(
                new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)))
                );

            var batch = new CompositionBatch();

            var fileStream = new FileStream(LocalSettings.ClientXmlFilePath, FileMode.OpenOrCreate, FileAccess.Read);
            _settings = SettingsManager.LoadSettings<LocalSettings>(fileStream);

            if (_settings == null)
            {
                _settings = new LocalSettings { FirstRun = true };
            }
            else
            {
                _settings.FirstRun = false;
            }

            batch.AddExportedValue(_settings);
            batch.AddExportedValue<IWindowManager>(new WindowManager());
            batch.AddExportedValue<IEventAggregator>(new EventAggregator());
            batch.AddExportedValue(_container);

            _container.Compose(batch);
        }
开发者ID:fcin,项目名称:RemindMe,代码行数:27,代码来源:Bootstrapper.cs

示例8: OnStartup

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            #if (DEBUG != true)
            // Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't
            // jump into the code when an exception occurs.
            DispatcherUnhandledException += AppDispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
            #endif

            catalog = new AggregateCatalog();
            // Add the WpfApplicationFramework assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly));

            // Load module assemblies as well. See App.config file.
            foreach (string moduleAssembly in Settings.Default.ModuleAssemblies)
            {
                catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly));
            }

            container = new CompositionContainer(catalog);
            CompositionBatch batch = new CompositionBatch();
            batch.AddExportedValue(container);
            container.Compose(batch);

            // Initialize all presentation services
            var presentationServices = container.GetExportedValues<IPresentationService>();
            foreach (var presentationService in presentationServices) { presentationService.Initialize(); }

            // Initialize and run all module controllers
            moduleControllers = container.GetExportedValues<IModuleController>();
            foreach (var moduleController in moduleControllers) { moduleController.Initialize(); }
            foreach (var moduleController in moduleControllers) { moduleController.Run(); }
        }
开发者ID:hliang89,项目名称:WpfApplicationFramework,代码行数:35,代码来源:App.xaml.cs

示例9: OnStartup

        protected override void OnStartup( StartupEventArgs e )
        {
            base.OnStartup( e );

            new UnhandledExceptionHook( this );

            Application.Current.Exit += OnShutdown;

            var catalog = new AssemblyCatalog( GetType().Assembly );
            myContainer = new CompositionContainer( catalog, CompositionOptions.DisableSilentRejection );

            myContainer.Compose( new CompositionBatch() );

            var shell = myContainer.GetExportedValue<Shell>();

            myContainer.SatisfyImportsOnce( shell.myDesigner );

            ( ( Shell )MainWindow ).myProperties.DataContext = shell.myDesigner.SelectionService;

            Application.Current.MainWindow = shell;
            Application.Current.MainWindow.Show();

            var args = Environment.GetCommandLineArgs();
            if( args.Length == 2 )
            {
                shell.myDesigner.Open( args[ 1 ] );
            }
        }
开发者ID:JackWangCUMT,项目名称:Plainion.Whiteboard,代码行数:28,代码来源:App.xaml.cs

示例10: ConventionCatalog_should_support_type_exports

        public void ConventionCatalog_should_support_type_exports()
        {
            var registry = new PartRegistry();
            registry.TypeScanner = new AssemblyTypeScanner(Assembly.GetExecutingAssembly());

            registry
                .Part()
                .ForType<SampleExport>()
                .Export();

            var catalog =
               new ConventionCatalog(registry);

            var instance =
                new ConventionPart<SampleExport>();

            var batch =
                new CompositionBatch();
            batch.AddPart(instance);

            var container =
                new CompositionContainer(catalog);

            container.Compose(batch);

            instance.Imports.Count().ShouldEqual(1);
        }
开发者ID:doublekill,项目名称:MefContrib,代码行数:27,代码来源:IntegrationTests.cs

示例11: DualContainers

        public void DualContainers()
        {
            var container1 = new CompositionContainer();
            TypeDescriptorServices dat1 = new TypeDescriptorServices();
            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(dat1);
            container1.Compose(batch);
            MetadataStore.AddAttribute(
                typeof(DynamicMetadataTestClass),
                ( type, attributes) => 
                    Enumerable.Concat(
                        attributes,
                        new Attribute[] { new TypeConverterAttribute(typeof(DynamicMetadataTestClassConverter)) }
                    ),
                container1
            );


            var container2 = new CompositionContainer();
            CompositionBatch batch2 = new CompositionBatch();
            TypeDescriptorServices dat2 = new TypeDescriptorServices();
            batch2.AddPart(dat2);
            container2.Compose(batch2);

            DynamicMetadataTestClass val = DynamicMetadataTestClass.Get("42");

            var attached1 = dat1.GetConverter(val.GetType());
            Assert.IsTrue(attached1.CanConvertFrom(typeof(string)), "The new type converter for DynamicMetadataTestClass should support round tripping");

            var attached2 = dat2.GetConverter(val.GetType());
            Assert.IsFalse(attached2.CanConvertFrom(typeof(string)), "The default type converter for DynamicMetadataTestClass shouldn't support round tripping");
        }
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:DynamicMetadata.cs

示例12: Compose

 private void Compose()
 {
     var container = new CompositionContainer(directories);
       var batch = new CompositionBatch();
       batch.AddPart(this);
       container.Compose(batch);
 }
开发者ID:edgar-pek,项目名称:VCDryad,代码行数:7,代码来源:PluginManager.cs

示例13: Compose

        public void Compose(BaseParameters parameters)
        {
            try
            {
                var catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()),
                                                   new AssemblyCatalog(typeof(Logic.SanityCheck).Assembly));

                LoadPlugins(catalog, parameters);

                var container = new CompositionContainer(catalog);

                var batch = new CompositionBatch();
                batch.AddPart(this);
                batch.AddPart(parameters);

                var config = new Configuration(parameters.FileSystem, parameters.Path);
                config.ReadFromFile();
                batch.AddExportedValue((IConfiguration)config);

                container.Compose(batch);
            }
            catch (ReflectionTypeLoadException ex)
            {
                Console.WriteLine(@"Unable to load: \r\n{0}",
                    string.Join("\r\n", ex.LoaderExceptions.Select(e => e.Message)));

                throw;
            }
        }
开发者ID:Code52,项目名称:pretzel,代码行数:29,代码来源:Program.cs

示例14: Compose

        public void Compose()
        {
            AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string generatorsPath = Path.Combine(executionPath, "Generators");
            CreatePathIfRequied(generatorsPath);
            generatorsCatalog = new DirectoryCatalog(generatorsPath);

            string uiPath = Path.Combine(executionPath, "UI");
            CreatePathIfRequied(uiPath);
            UICatalog = new DirectoryCatalog(uiPath);

            AggregateCatalog catalog = new AggregateCatalog();
            catalog.Catalogs.Add(generatorsCatalog);
            catalog.Catalogs.Add(UICatalog);

            //Set the defaults....
            CatalogExportProvider mainProvider = new CatalogExportProvider(assemblyCatalog);
            CompositionContainer container = new CompositionContainer(catalog, mainProvider);
            mainProvider.SourceProvider = container;

            var batch = new CompositionBatch();
            batch.AddPart(this);

            RefreshCatalog refreshCatalog = new RefreshCatalog(generatorsCatalog, UICatalog);
            container.ComposeParts(refreshCatalog);
            container.Compose(batch);

            Logger.Write("Compose complete");
        }
开发者ID:BenHall,项目名称:ExtendViaMEF,代码行数:32,代码来源:Extender.cs

示例15: Compose

        private bool Compose()
        {
            var catalog = new System.ComponentModel.Composition.Hosting.AggregateCatalog();
            //            var catalog = new AggregatingComposablePartCatalog();
            catalog.Catalogs.Add(
                new RubyCatalog(new RubyPartFile("calculator_ops.rb")));
            catalog.Catalogs.Add(
                new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            _container = new System.ComponentModel.Composition.Hosting.CompositionContainer(catalog);
            //_container. AddPart(this);
            var batch = new System.ComponentModel.Composition.Hosting.CompositionBatch();
            batch.AddPart(this);
            //_container.AddPart(this);
            //_container.Compose(this);

            try
            {
                _container.Compose(batch);
            }
            catch (CompositionException compositionException)
            {
                MessageBox.Show(compositionException.ToString());
                return false;
            }
            return true;
        }
开发者ID:JogoShugh,项目名称:IronRubyMef,代码行数:26,代码来源:App.xaml.cs


注:本文中的System.ComponentModel.Composition.Hosting.CompositionContainer.Compose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。