當前位置: 首頁>>代碼示例>>C#>>正文


C# AggregateCatalog.Dispose方法代碼示例

本文整理匯總了C#中System.ComponentModel.Composition.Hosting.AggregateCatalog.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# AggregateCatalog.Dispose方法的具體用法?C# AggregateCatalog.Dispose怎麽用?C# AggregateCatalog.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ComponentModel.Composition.Hosting.AggregateCatalog的用法示例。


在下文中一共展示了AggregateCatalog.Dispose方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Configure

        /// <summary>
        /// MEF Bootstrap (MEF comes from System.ComponentModel.Composition in the GAC).
        /// <para>This will return a class containing all the application's aggregate roots.</para>
        /// </summary>
        public static ComposedDemoProgram Configure(params string[] pluginDirectories)
        {
            var catalogues = 
                pluginDirectories.Select<string, ComposablePartCatalog>(d=>new DirectoryCatalog(d)).
                Concat(new []{new AssemblyCatalog(Assembly.GetExecutingAssembly())}).ToList();

            var catalog = new AggregateCatalog(catalogues);
            try
            {
                var container = new CompositionContainer(catalog);

                var composedProgram = new ComposedDemoProgram();
                container.SatisfyImportsOnce(composedProgram);

                return composedProgram;
            }
            finally
            {
                catalog.Dispose();
                foreach (var cat in catalogues)
                {
                    cat.Dispose();
                }
            }
        }
開發者ID:mind0n,項目名稱:hive,代碼行數:29,代碼來源:Program.cs

示例2: Initialize

        /// <summary>
        ///     This method can be used to initialize the global container used by <see cref="CompositionInitializer.SatisfyImports(object)"/>
        ///     in case where the default container doesn't provide enough flexibility. 
        ///     
        ///     If this method is needed it should be called exactly once and as early as possible in the application host. It will need
        ///     to be called before the first call to <see cref="CompositionInitializer.SatisfyImports(object)"/>
        /// </summary>
        /// <param name="catalogs">
        ///     An array of <see cref="ComposablePartCatalog"/> that should be used to initialize the <see cref="CompositionContainer"/> with.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="catalogs"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        ///     Either <see cref="Initialize(CompositionContainer)" /> or <see cref="Initialize(ComposablePartCatalog[])" />has already been called or someone has already made use of the global 
        ///     container via <see cref="CompositionInitializer.SatisfyImports(object)"/>. In either case you need to ensure that it 
        ///     is called only once and that it is called early in the application host startup code.
        /// </exception>
        public static CompositionContainer Initialize(params ComposablePartCatalog[] catalogs)
        {
            AggregateCatalog aggregateCatalog = new AggregateCatalog(catalogs);
            CompositionContainer container = new CompositionContainer(aggregateCatalog);
            try
            {
                CompositionHost.Initialize(container);
            }
            catch
            {
                container.Dispose();

                // NOTE : this is important, as this prevents the disposal of the catalogs passed as input arguments
                aggregateCatalog.Catalogs.Clear();
                aggregateCatalog.Dispose();

                throw;
            }

            return container;
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:39,代碼來源:CompositionHost.cs

示例3: AggregatingDisposedAndNotifications

        public void AggregatingDisposedAndNotifications()
        {
            int changedCount = 0;
            int typesChanged = 0;

            EventHandler<ComposablePartCatalogChangeEventArgs> onChanged = delegate(object sender, ComposablePartCatalogChangeEventArgs e)
            {
                ++changedCount;
                typesChanged += e.AddedDefinitions.Concat(e.RemovedDefinitions).Count();
            };

            // Create our child catalogs
            AggregateCatalog[] mainChildren;
            AggregateCatalog[] otherChildren;
            TypeCatalog[] componentCatalogs;
            CreateMainAndOtherChildren(out mainChildren, out otherChildren, out componentCatalogs);


            var parent = new AggregateCatalog(mainChildren);
            parent.Changed += onChanged;

            for (int i = 0; i < otherChildren.Length; i++)
            {
                parent.Catalogs.Add(otherChildren[i]);
            }

            Assert.AreEqual(otherChildren.Length, changedCount);
            Assert.AreEqual(otherChildren.Length * 3, typesChanged);

            changedCount = 0;
            typesChanged = 0;

            parent.Dispose();

            Assert.AreEqual(0, changedCount);
            Assert.AreEqual(0, typesChanged);

            //Ensure that the children are also disposed
            ExceptionAssert.ThrowsDisposed(otherChildren[0], () =>
            {
                otherChildren[0].Catalogs.Remove(componentCatalogs[0]);
            });

            //Ensure that the children are also disposed
            ExceptionAssert.ThrowsDisposed(otherChildren[4], () =>
            {
                otherChildren[4].Catalogs.Remove(componentCatalogs[0]);
            });

            Assert.AreEqual(0, changedCount);
            Assert.AreEqual(0, typesChanged);
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:52,代碼來源:AggregateCatalogTest.cs


注:本文中的System.ComponentModel.Composition.Hosting.AggregateCatalog.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。