JUGEMテーマ:コンピュータ
AggregateExportProvider クラス
ExportProvider オブジェクトのコレクションによって提供されるエクスポートを集約します。 名前空間: System.ComponentModel.Composition.Hosting
アセンブリ: System.ComponentModel.Composition (System.ComponentModel.Composition.dll 内)
AggregateExportProviderクラスを使ってみました。
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
AggregateExportProvider クラス
ExportProvider オブジェクトのコレクションによって提供されるエクスポートを集約します。 名前空間: System.ComponentModel.Composition.Hosting
アセンブリ: System.ComponentModel.Composition (System.ComponentModel.Composition.dll 内)
AggregateExportProviderクラスを使ってみました。
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
namespace MEFSample
{
class Program
{
static void Main(string[] args)
{
var catalog = new AggregateCatalog(new TypeCatalog(typeof(A), typeof(B), typeof(C)));
var provider = new AggregateExportProvider(new CatalogExportProvider(catalog));
var container = new CompositionContainer(catalog, provider);
IA a = container.GetExportedValue<IA>();
a.Say();
}
}
{
class Program
{
static void Main(string[] args)
{
var catalog = new AggregateCatalog(new TypeCatalog(typeof(A), typeof(B), typeof(C)));
var provider = new AggregateExportProvider(new CatalogExportProvider(catalog));
var container = new CompositionContainer(catalog, provider);
IA a = container.GetExportedValue<IA>();
a.Say();
}
}
public interface IA
{
void Say();
}
{
void Say();
}
public interface IB
{
void Say();
}
{
void Say();
}
public interface IC
{
void Say();
}
{
void Say();
}
[Export(typeof(IA))]
class A : IA
{
[Import]
public IB B { get; set; }
class A : IA
{
[Import]
public IB B { get; set; }
public void Say()
{
B.Say();
}
}
{
B.Say();
}
}
[Export(typeof(IB))]
class B : IB
{
[Import]
public IC C { get; set; }
class B : IB
{
[Import]
public IC C { get; set; }
public void Say()
{
C.Say();
}
}
{
C.Say();
}
}
[Export(typeof(IC))]
class C : IC
{
public void Say()
{
Console.WriteLine("C Say");
}
}
}
カタログ、プロバイダー(コンテナ)、エックスポート、インポート・・・いろいろ覚えることありますね。
class C : IC
{
public void Say()
{
Console.WriteLine("C Say");
}
}
}
カタログ、プロバイダー(コンテナ)、エックスポート、インポート・・・いろいろ覚えることありますね。
- 2010.05.21 Friday
- MEF
- 01:15
- comments(0)
- trackbacks(0)


- by art55


















