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


C# CompositionContainer.ComposeParts方法代码示例

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


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

示例1: Application_Startup

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var assembly =
               new AssemblyCatalog(Assembly.GetEntryAssembly());


            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(assembly);
            catalog.Catalogs.Add(new DirectoryCatalog("."));


            var compositionContainer
                = new CompositionContainer(catalog);
            compositionContainer.ComposeParts(this);

            var locator = new MefServiceLocator(compositionContainer);
            ServiceLocator.SetLocatorProvider(() => locator);


            ViewModelManager.ViewModelShowEvent
                += vm => ViewManager.ViewShow(vm);
            ViewModelManager.ViewModelCloseEvent
                += vm => ViewManager.ViewClose(vm);

            var mainWindowViewModel = new MainWindowViewModel();
            compositionContainer.ComposeParts(mainWindowViewModel);
           
            MainWindow mainWindow = new MainWindow {DataContext = mainWindowViewModel};
            mainWindow.Show();
        }
开发者ID:Whylex,项目名称:ikit-mita-materials,代码行数:30,代码来源:App.xaml.cs

示例2: ExtensionContainer

 /// <summary>
 /// Default constructor. Creates a new extension container and registers all
 /// exported objects.
 /// </summary>
 public ExtensionContainer()
 {
     var catalog = new AggregateCatalog() ;
     catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())) ;
     Container = new CompositionContainer(catalog) ;
     Container.ComposeParts(this) ;
 }
开发者ID:springzh,项目名称:Piranha,代码行数:11,代码来源:ExtensionContainer.cs

示例3: AssembleComponents

        /// <summary>
        /// This method loads the plugins.
        /// </summary>
        private void AssembleComponents()
        {
            var catalog = new AggregateCatalog();

            //Note: we load not only from the plugins folder, but from this assembly as well.
            var executingAssemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            if (Directory.Exists(Environment.CurrentDirectory + "\\Plugins"))
            {
                catalog.Catalogs.Add(new DirectoryCatalog("Plugins"));
            }

            catalog.Catalogs.Add(executingAssemblyCatalog);

            var container = new CompositionContainer(catalog);

            try
            {
                container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                _dialogService.ShowMessageAsync(_mainVm, "Error", string.Format("There was an error loading plugins: {0}", compositionException)).Forget();
            }
        }
开发者ID:QANTau,项目名称:QPAS,代码行数:28,代码来源:StatementHandler.cs

示例4: TestMefStatusReportable

        public void TestMefStatusReportable()
        {
            string dir = AssemblyDirectory;

            //Lets get the nlog status reportable from MEF directory..
            CompositionContainer _container;
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();
            //Adds all the parts found in the same assembly as the Program class
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestMEF).Assembly));
            catalog.Catalogs.Add(new DirectoryCatalog(AssemblyDirectory));

            //Create the CompositionContainer with the parts in the catalog
            _container = new CompositionContainer(catalog);

            //Fill the imports of this object
            try
            {
               _container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }

            reporter.Report(2,1,"Test Report");
        }
开发者ID:framirezh,项目名称:encog-dotnet-core,代码行数:27,代码来源:TestMEF.cs

示例5: ExtensionManager

        /// <summary>
        /// Default private constructor.
        /// </summary>
        private ExtensionManager()
        {
            if (!Config.DisableComposition)
            {
                // Let MEF scan for imports
                var catalog = new AggregateCatalog();

                catalog.Catalogs.Add(Config.DisableCatalogSearch ? new DirectoryCatalog("Bin", "Piranha*.dll") : new DirectoryCatalog("Bin"));

            #if !NET40
                if (!System.Web.Compilation.BuildManager.IsPrecompiledApp)
                {
            #endif
                    try
                    {
                        // This feature only exists for Web Pages
                        catalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load("App_Code")));
                    }
                    catch { }
            #if !NET40
                }
            #endif

                Container = new CompositionContainer(catalog);
                Container.ComposeParts(this);
            }
        }
开发者ID:cnascimento,项目名称:Paladino,代码行数:30,代码来源:ExtensionManager.cs

示例6: Main

		public static void Main (string[] args)
		{
			var bootStrapper = new Bootstrapper();

            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();
            //Adds all the parts found in same directory where the application is running!
            var currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(MainClass)).Location) ?? "./";
            catalog.Catalogs.Add(new DirectoryCatalog(currentPath));

            //Create the CompositionContainer with the parts in the catalog
            var container = new CompositionContainer(catalog);
            
            //Fill the imports of this object
            try
            {
                container.ComposeParts(bootStrapper);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }

            //Prints all the languages that were found into the application directory
            var i = 0;
            foreach (var language in bootStrapper.Languages)
            {
                Console.WriteLine("[{0}] {1} by {2}.\n\t{3}\n", language.Version, language.Name, language.Author, language.Description);
                i++;
            }
            Console.WriteLine("It has been found {0} supported languages",i);
            Console.ReadKey();
		}
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:33,代码来源:Main.cs

示例7: Initialize

        /// <summary>
        /// Initializes the MEF Container.
        /// </summary>
        /// <param name="root">The root.</param>
        public static void Initialize(object root)
        {
            if (root == null)
            throw new NullReferenceException("MEF root");

             if (_instance == null) {
            lock (_syncRoot) {
               if (_instance == null) {
                  string exePath = null;
                  string path = null;
                  if (Assembly.GetEntryAssembly() != null) {
                     exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                  } else {
                     exePath = Path.GetDirectoryName(root.GetType().Assembly.Location);
                  }
                  path = Path.Combine(exePath, "\\plugins");
                  if (!Directory.Exists(path))
                     Directory.CreateDirectory(path);

                  var catalog = new AggregateCatalog();
                  if (path != null)
                     catalog.Catalogs.Add(new DirectoryCatalog(path));
                  if (exePath != null)
                     catalog.Catalogs.Add(new DirectoryCatalog(exePath));
                  catalog.Catalogs.Add(new AssemblyCatalog(root.GetType().Assembly));

                  _instance = new CompositionContainer(catalog);
                  _instance.ComposeParts(root);

               }
            }
             }
        }
开发者ID:Cappinator,项目名称:chiiilp-pbem,代码行数:37,代码来源:MEFContainer.cs

示例8: Start

        public void Start()
        {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(SearchDemo).Assembly));
            var container = new CompositionContainer(catalog);
            container.ComposeParts();

            try
            {
                var component = container.GetExport<ITestComponent>();
                if (component != null)
                    Console.WriteLine(component.Value.Message);
            }
            catch (Exception exp)
            {
                //Why does our call to 'GetExport' throw an exception?

                //Search for the string "Test" on the container variable
                //You'll find 3 instances in the Catalog.
                //Then search for ITestComponent.
                //You'll need to click "Search Deeper" to expand the search.

                //Another way to do this is to view "container.Catalog.Parts", right click it,
                //select 'Edit Filter' and enter the following predicate:
                //         [obj].Exports(typoef(ITestComponent)

                MessageBox.Show(exp.Message, "Exception caught!");
            }
        }
开发者ID:OmerRaviv,项目名称:OzCodeDemo,代码行数:30,代码来源:SearchDemo.cs

示例9: LinkThumbnailScreenFactory

        public LinkThumbnailScreenFactory(CompositionContainer compositionContainer, 
            Factories.ImageThumbnailScreenFactory imageThumbnailScreenFactory)
        {
            _imageThumbnailScreenFactory = imageThumbnailScreenFactory;

            compositionContainer.ComposeParts(this);
        }
开发者ID:GraemeF,项目名称:Twiddler,代码行数:7,代码来源:LinkThumbnailScreenFactory.cs

示例10: Setup

        public void Setup()
        {
            aggregateCatalog = new AggregateCatalog();
            container = new CompositionContainer(aggregateCatalog);

            container.ComposeParts(this);
        }
开发者ID:aklefdal,项目名称:TinyMVVM,代码行数:7,代码来源:MEFLearningTests.cs

示例11: Bootstrap

        private void Bootstrap()
        {
            _jobModelRegistry = new ConcurrentDictionary<string, JobModel>();

            _compositionContainer = new CatalogConfigurator()
               .AddAssembly(Assembly.GetExecutingAssembly())
               .AddNestedDirectory(Config.JobsFolderName)
               .BuildContainer();


            _compositionContainer.ComposeParts(this);

            InitTasksRegistry();

            _appContainerBuilder = new ContainerBuilder();
            _appContainerBuilder.RegisterModule<WorkerModule>();
            _appContainerBuilder.RegisterModule<HostingModule>();
            _appContainer = _appContainerBuilder.Build();

            //TODO: make onchanged to an event
            _fileSystemWatcher = new JobsWatcher { OnChanged = OnChanged };
            _fileSystemWatcher.Watch(TasksFolderPath);

            _logger = _appContainer.Resolve<ILogger>();

            _logger.Info("[START] PanteonEngine");

            Task.Run(() => MountApi());
        }
开发者ID:PanteonProject,项目名称:Panteon.Host,代码行数:29,代码来源:PanteonEngine.cs

示例12: compose

        private bool compose()
        {
            try {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(@".\plugins"));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            var container = new CompositionContainer(catalog);
            container.ComposeParts(this);

            var builder = new ContainerBuilder();
            builder.Register((c, p) => new JsonGopherConfigReader(gopherRepositoryManager)).As<IConfigReader>();
            Container = builder.Build(Autofac.Builder.ContainerBuildOptions.Default);

            return true;
              } catch (CompositionException ex) {
            if (Logger != null) {
              Logger.ErrorException("Unable to compose", ex);
            }
            System.Console.WriteLine(ex);
            return false;
              } catch (Exception ex) {
            if (Logger != null) {
              Logger.ErrorException("Unable to compose", ex);
            }
            System.Console.WriteLine(ex);
            return false;
              }
        }
开发者ID:andyjmay,项目名称:Gopher,代码行数:28,代码来源:Program.cs

示例13: CodeProcessorProvider

#pragma warning restore 649

		private CodeProcessorProvider() {
			var catalog = new AggregateCatalog();
			catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
			catalog.Catalogs.Add(new DirectoryCatalog("."));
			var container = new CompositionContainer(catalog);
			container.ComposeParts(this);
		}
开发者ID:UnicoenProject,项目名称:UniAspect,代码行数:9,代码来源:CodeProcessorProvider.cs

示例14: MyClassInitialize

 public static void MyClassInitialize(TestContext testContext)
 {
   // set uo IoC container to use MyRootFakeData
   var container = new CompositionContainer();
   container.ComposeParts(new MyRootFakeData());
   CslaContrib.MEF.Ioc.InjectContainer(container);
 }
开发者ID:transformersprimeabcxyz,项目名称:cslacontrib-MarimerLLC,代码行数:7,代码来源:MyRootTest.cs

示例15: Run

 public void Run()
 {
     CompositionContainer _CompositionContainer = new CompositionContainer(new ConfigExportProvider());
     _CompositionContainer.ComposeParts(this);
     CodeCamp.DataServerInterface.IDataServer _DataServer = DataServer;// new DataServer();
     Person _Person = new Person();
     Sponsor _Sponsor = new Sponsor();
     _DataServer.Add<Sponsor>(_Sponsor);
     _DataServer.Add<Person>(_Person);
     _DataServer.Commit();
     IQueryable<Sponsor> _Sponsors = _DataServer.GetTable<Sponsor>();
     Console.WriteLine(_Sponsors.ToList().Count().ToString());
     //
     IQueryable<Person> _Persons = _DataServer.GetTable<Person>();
     Console.WriteLine(_Persons.ToList().Count().ToString());
     //modify a persom
     string _NewName = "Changed:" + DateTime.Now.ToString();
     _Persons.First().Name = _NewName;
     _DataServer.Commit();
     _Person = _DataServer.GetTable<Person>().Where(x => x.Name == _NewName).FirstOrDefault();
     if (_Person == null)
         throw new Exception("Person name not changed");
     Console.WriteLine(_Person.Name);
     Console.ReadLine();
 }
开发者ID:onetug,项目名称:CodeCamp2011,代码行数:25,代码来源:Program.cs


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