私は IntelliSense の実装を作成しており、VisualStudio のアイコン セットにアクセスしようとしています。MEF を使用するつもりであり、インポートするプロパティ/フィールドが自動的に入力される必要があることを理解しています。現在私は持っています:
[Import]
public IGlyphService GlyphService { get; set; }
GlyphService は常に null です。私は何が欠けていますか?
私は IntelliSense の実装を作成しており、VisualStudio のアイコン セットにアクセスしようとしています。MEF を使用するつもりであり、インポートするプロパティ/フィールドが自動的に入力される必要があることを理解しています。現在私は持っています:
[Import]
public IGlyphService GlyphService { get; set; }
GlyphService は常に null です。私は何が欠けていますか?
どうやら、CompositionContainer を手動で入力して構成する必要があるようです。私のソリューションは次のようになります。
// An aggregate catalog that combines multiple catalogs
var catalog = new AggregateCatalog();
// Adds all the parts found in the necessary assemblies
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IGlyphService).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(SmartTagSurface).Assembly));
// Create the CompositionContainer with the parts in the catalog
CompositionContainer mefContainer = new CompositionContainer(catalog);
// Fill the imports of this object
mefContainer.ComposeParts(this);
これを実行すると、現在のオブジェクト (または構成パーツで選択したオブジェクト) にインポートが設定されます。プログラムのbinフォルダーに参照されているdllを含める必要があるなど、これに関していくつかの問題に遭遇しました。