• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Hosting.CompositionBatch类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



CompositionBatch类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了CompositionBatch类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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


示例2: 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


示例3: OnComponentRegistrationOnActivated

 private void OnComponentRegistrationOnActivated(object sender, ActivatedEventArgs<object> activation_event)
 {
     // compose by batch to allow for recomposition
     var batch = new CompositionBatch();
     batch.AddPart(activation_event.Instance);
     _mefContainer.Compose(batch);
 }
开发者ID:brunomlopes,项目名称:ILoveLucene,代码行数:7,代码来源:SatisfyMefImports.cs


示例4: Configure

        /// <summary>
        /// By default, we are configured to use MEF
        /// </summary>
        protected override void Configure()
        {
            // Add all assemblies to AssemblySource (using a temporary DirectoryCatalog).
            var directoryCatalog = new DirectoryCatalog(@"./");
            AssemblySource.Instance.AddRange(
                directoryCatalog.Parts
                    .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                    .Where(assembly => !AssemblySource.Instance.Contains(assembly)));

            // Prioritise the executable assembly. This allows the client project to override exports, including IShell.
            // The client project can override SelectAssemblies to choose which assemblies are prioritised.
            var priorityAssemblies = SelectAssemblies().ToList();
            var priorityCatalog = new AggregateCatalog(priorityAssemblies.Select(x => new AssemblyCatalog(x)));
            var priorityProvider = new CatalogExportProvider(priorityCatalog);

            // Now get all other assemblies (excluding the priority assemblies).
            var mainCatalog = new AggregateCatalog(
                AssemblySource.Instance
                    .Where(assembly => !priorityAssemblies.Contains(assembly))
                    .Select(x => new AssemblyCatalog(x)));
            var mainProvider = new CatalogExportProvider(mainCatalog);

            Container = new CompositionContainer(priorityProvider, mainProvider);
            priorityProvider.SourceProvider = Container;
            mainProvider.SourceProvider = Container;

            var batch = new CompositionBatch();

            BindServices(batch);
            batch.AddExportedValue(mainCatalog);

            Container.Compose(batch);
        }
开发者ID:4ux-nbIx,项目名称:gemini,代码行数:36,代码来源:AppBootstrapper.cs


示例5: Init

        public Runner Init(IFeedbackProvider feedbackProvider, string[] args)
        {
            var catalog = new AggregateCatalog(new AssemblyCatalog(typeof(Bootstrapper).Assembly));

            var currentDir = Environment.CurrentDirectory;
            var assemblyDir = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath).Directory.FullName;

            var paths = new string[]
            {
                assemblyDir,
                Path.Combine(assemblyDir, "Tasks"),
                currentDir,
                Path.Combine(currentDir, "Tasks")
            }.Unique();

            var dirCatalogs = paths.Where(x => Directory.Exists(x))
                                   .Select(x => new DirectoryCatalog(x, "*.Tasks.dll"));
            dirCatalogs.Apply(x => catalog.Catalogs.Add(x));

            var container = new CompositionContainer(catalog);

            var parsed = new ArgumentParser().Parse(args);
            var runner = new Runner(parsed.ActualArgs.ToArray());

            var batch = new CompositionBatch();
            batch.AddExportedValue<IFeedbackProvider>(feedbackProvider);
            parsed.Options.Apply(x => batch.AddExportedValue<string>(x.Item1, x.Item2));
            parsed.Switches.Apply(x => batch.AddExportedValue<bool>(x, true));
            batch.AddPart(runner);
            container.Compose(batch);

            return runner;
        }
开发者ID:mikeminutillo,项目名称:task,代码行数:33,代码来源:Bootstrapper.cs


示例6: SatisfyImportsOnce

        public void SatisfyImportsOnce(ComposablePart part)
        {
            if (this.DoNothingOnSatisfyImportsOnce)
            {
                return;
            }

            CompositionBatch batch = new CompositionBatch();

            // We only want to include the standard exports and parts to compose in the first composition
            if (!this.alreadyComposed)
            {
                foreach (object instance in this.PartsToCompose)
                {
                    batch.AddPart(instance);
                }

                foreach (Export export in this.ExportsToCompose)
                {
                    batch.AddExport(export);
                }
            }

            if (part != null)
            {
                batch.AddPart(part);
            }

            this.container.Compose(batch);
            this.alreadyComposed = true;
        }
开发者ID:SonarSource-VisualStudio,项目名称:sonarlint-visualstudio,代码行数:31,代码来源:ConfigurableCompositionService.cs


示例7: 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


示例8: SatisfyImports

        /// <summary>
        ///     Will satisfy the imports on a object instance based on a <see cref="CompositionContainer"/>
        ///     registered with the <see cref="CompositionHost"/>. By default if no <see cref="CompositionContainer"/>
        ///     is registered the first time this is called it will be initialized to a catalog
        ///     that contains all the assemblies loaded by the initial application XAP.
        /// </summary>
        /// <param name="instance">
        ///     Object instance that contains <see cref="ImportAttribute"/>s that need to be satisfied.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="instance"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="instance"/> contains <see cref="ExportAttribute"/>s applied on its type.
        /// </exception>
        /// <exception cref="ChangeRejectedException">
        ///     One or more of the imports on the object instance could not be satisfied.
        /// </exception>
        /// <exception cref="CompositionException">
        ///     One or more of the imports on the object instance caused an error while composing.
        /// </exception>
        public static void SatisfyImports(object instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            var batch = new CompositionBatch();

            var attributedPart = batch.AddPart(instance);

            if (attributedPart.ExportDefinitions.Any())
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                        "Cannot call SatisfyImports on a object of type '{0}' because it is marked with one or more ExportAttributes.",
                        instance.GetType().FullName), "instance");
            }

            CompositionContainer container = null;

            // Ignoring return value because we don't need to know if we created it or not
            CompositionHost.TryGetOrCreateContainer(_createContainer, out container);

            container.Compose(batch);
        }
开发者ID:dsplaisted,项目名称:MEFBook,代码行数:46,代码来源:CompositionInitializer.cs


示例9: 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


示例10: RestServer

 public RestServer(ushort port)
     : base(port)
 {
     this.HttpRequestReceived += new EventHandler<HttpServerEventArgs>(RestServer_RequestReceived);
     batch = new CompositionBatch();
     batch.AddPart(this);
 }
开发者ID:RoyDoron,项目名称:bonjour.net,代码行数:7,代码来源:RestServer.cs


示例11: MainForm

        /// <summary>
        /// Initialises a new instance of the <see cref="MainForm"/> class.
        /// </summary>
        public MainForm()
        {
            this.InitializeComponent();

            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog("..\\..\\Crypto", "*.dll"));
            var batch = new CompositionBatch();
            batch.AddPart(this);
            this.compositionContainer = new CompositionContainer(catalog);
            ////get all the exports and load them into the appropriate list tagged with the importmany
            this.compositionContainer.Compose(batch);

            this.CryptoAlgorithmComboBox.DataSource = (new List<CryptoAlgorithm> { CryptoAlgorithm.None }).Union(
                this.CryptoProviders.Select(c => c.Metadata.Algorithm).Distinct()).ToList();

            this.JoinedUsers = new BindingList<User>();

            this.ConnectedUsersDataGridView.DataSource = this.JoinedUsers;
            this.userProxy = new UserServiceClient(new InstanceContext(this));

            this.userProxy.Open();
            this.messagingProxy = new MessagingServiceClient(new InstanceContext(this));
            this.messagingProxy.Open();

            this.userProxy.Subscribe();
            foreach (var u in this.userProxy.GetJoinedUsers())
            {
                this.AddUser(u);
            }

            this.uiSyncContext = SynchronizationContext.Current;
        }
开发者ID:famstutz,项目名称:YAEM,代码行数:35,代码来源:MainForm.cs


示例12: 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


示例13: 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


示例14: 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


示例15: 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));
            // Add the Waf.BookLibrary.Library.Presentation assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            // Add the Waf.BookLibrary.Library.Applications assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly));

            // Load module assemblies as well (e.g. Reporting extension). 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);

            moduleControllers = container.GetExportedValues<IModuleController>();
            foreach (IModuleController moduleController in moduleControllers) { moduleController.Initialize(); }
            foreach (IModuleController moduleController in moduleControllers) { moduleController.Run(); }
        }
开发者ID:PeterQin,项目名称:HiClock,代码行数:34,代码来源:App.xaml.cs


示例16: BindServices

        protected virtual void BindServices(CompositionBatch batch)
        {
            try
            {
                _tinyIoCContainer = new TinyIoCContainer();
                var eventAggregator = new EventAggregator();

                // Defaults
                batch.AddExportedValue<IWindowManager>(new WindowManager());
                batch.AddExportedValue<IEventAggregator>(eventAggregator);

                // framework and infrastructure
                _tinyIoCContainer.Register<IEventAggregator>(eventAggregator);
                // _tinyIoCContainer.Register<IServiceLocator>(new TinyServiceLocator(_container));
                _tinyIoCContainer.RegisterMultiple<IMessageEventSubscriber>(new[] {typeof (EventMessageListener)})
                    .AsSingleton();

                // register other implementations
                DependencyFactory.Configure(_tinyIoCContainer);

                // Export IoC registrations
                batch.AddExportedValue(_tinyIoCContainer.Resolve<IRestartableMessageListener>());

                batch.AddExportedValue(Container);
            }
            catch (Exception e)
            {
                Log.Error(e, "Error on Bootstrapper BindServices: {CompositionBatch}", batch);
            }
        }
开发者ID:julianpaulozzi,项目名称:EntityProfiler,代码行数:30,代码来源:AppBootstrapper.cs


示例17: GetServiceLocator

        internal static IServiceLocator GetServiceLocator(Assembly assembly, CompositionBatch batch)
        {
            var assemblyLocation = assembly.Location;
            var file = new FileInfo(assemblyLocation);

            var catalogs = new List<ComposablePartCatalog>
            {
                new AssemblyCatalog(assembly),
                new DirectoryCatalog(file.DirectoryName ?? ".")
            };

            var catalog = new AggregateCatalog(catalogs);

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

            var serviceLocator = new MefServiceLocator(container);

            batch.AddExportedValue(container);
            batch.AddExportedValue<IServiceLocator>(serviceLocator);

            container.Compose(batch);

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


示例18: Configure

        /// <summary>Override to configure the framework and setup your IoC container.</summary>
        protected override void Configure()
        {
            // Add the assembly source to the catalog.
            // ReSharper disable once RedundantEnumerableCastCall
            var catalog = new AggregateCatalog(AssemblySource.Instance.Select(i => new AssemblyCatalog(i)).OfType<ComposablePartCatalog>());

            // Create a new composition container.
            // ReSharper disable once RedundantEnumerableCastCall
            this.container = new CompositionContainer();

            // Create a new composition container.
            this.container = new CompositionContainer(catalog);

            CompositionBatch compositionBatch = new CompositionBatch();

            // Add EventAggregator to composition batch.
            compositionBatch.AddExportedValue<IEventAggregator>(new EventAggregator());
            compositionBatch.AddExportedValue<IWindowManager>(new WindowManager());
            compositionBatch.AddExportedValue<ISettingsRepository>(new SettingsRepository());
            compositionBatch.AddExportedValue<ISolutionRepository>(new SolutionRepository());
            compositionBatch.AddExportedValue(new LogWriter(this.BuildLoggingConfiguration()));

            // Add the container itself.
            compositionBatch.AddExportedValue(this.container);

            // Compose the container.
            this.container.Compose(compositionBatch);
        }
开发者ID:Ruhrpottpatriot,项目名称:SkyrimCompileHelper,代码行数:29,代码来源:MefBootstrapper.cs


示例19: CreateExportProvider

 public ExportProvider CreateExportProvider(CompositionBatch additionalValues) {
     var container = new CompositionContainer(_catalogLazy.Value, CompositionOptions.DisableSilentRejection);
     AddValues(container);
     container.Compose(additionalValues);
     _containers.Enqueue(container);
     return container;
 }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:7,代码来源:MefCatalogFixture.cs


示例20: 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(ViewModel).Assembly));
            // Add the Waf.BookLibrary.Library.Presentation assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            // Add the Waf.BookLibrary.Library.Applications assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly));

            // Load module assemblies as well (e.g. Reporting extension). 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);

            moduleControllers = container.GetExportedValues<IModuleController>();
            foreach (IModuleController moduleController in moduleControllers) { moduleController.Initialize(); }
            foreach (IModuleController moduleController in moduleControllers) { moduleController.Run(); }
        }
开发者ID:bensenplus,项目名称:breeze,代码行数:30,代码来源:App.xaml.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Hosting.CompositionContainer类代码示例发布时间:2022-05-26
下一篇:
C# Hosting.AssemblyCatalog类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap