本文整理汇总了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();
}
}
}
示例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;
}
示例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);
}