2012-02-28 11 views
0

イム、私が持っている:MEFのみロード輸出

 var catalog = new AssemblyCatalog(typeof(Shell).Assembly); 
     var externalCatalog = new DirectoryCatalog(@".\Modules"); 

     var container = new CompositionContainer(catalog); 


     var a = new AggregateCatalog(externalCatalog, catalog); 

しかし、イムは、輸出を取得しよう:

 CompositionContainer __container = new CompositionContainer(a); 
     //get all the exports and load them into the appropriate list tagged with the importmany 
     __container.Compose(batch); 

     var yyyy = __container.GetExports<IModule>(); 

外部アセンブリ "Rejseplan"で自分の "IPlugin"が見つかりません。


"Rejseplan" プラグインの実装:(ロードされないもの)

namespace Rejseplan 
{ 

[ModuleExport(typeof(IPlugin), InitializationMode = InitializationMode.WhenAvailable)] 
class RejseplanModule : IModule, IPlugin 
{ 
    private readonly IRegionViewRegistry regionViewRegistry; 

    [ImportingConstructor] 
    public RejseplanModule(IRegionViewRegistry registry) 
    { 
     this.regionViewRegistry = registry; 
    } 

    public void Initialize() 
    { 
     regionViewRegistry.RegisterViewWithRegion("MainRegion", typeof(Views.DepartureBoard));  
    } 

    string IPlugin.Name 
    { 
     get { throw new NotImplementedException(); } 
    } 

    string IPlugin.Version 
    { 
     get { throw new NotImplementedException(); } 
    } 

    string IPlugin.TabHeader 
    { 
     get { throw new NotImplementedException(); } 
    } 
} 
} 

"テスト" プラグイン(ロードされるもの)のimplmentation:

namespace HomeSystem 
    { 
    [Export(typeof(IPlugin))] 
    [ModuleExport(typeof(IModule), InitializationMode = InitializationMode.WhenAvailable)] 
    public class Test : IModule, IPlugin 
    { 
    public void Initialize() 
    { 

    } 

    public string Name 
    { 
     get { return "Test"; } 
    } 

    public string Version 
    { 
     get { return "Tis"; } 
    } 

    public string TabHeader 
    { 
     get { return "Tabt"; } 
    } 
} 

}

皆さんお手伝い願います

乾杯! :)

+0

エラーが表示されるのですか、カタログにプラグインが一覧表示されていませんか? – blindmeis

+0

私のカタログのすべての部分を取得しました。私のプラグインのリストは、シェルDLL内のものだけを返します –

+0

重要な注意点:dllがロードされ、プログラム内のその領域にモジュールが表示されます。うまく動作しますが、モジュールのインスタンスを取得してそのデータをシェルから取得することはできません - (私はモジュールに関するシェルにいくつかのデータを表示したい) –

答えて

0

私は本当に :)あなたが達成したいものを知っていますが、通話中に自分のRejseplanModuleを見たい場合はいけない正直に言うと:

__container.GetExports<IModule>(); 

あなたは右のエクスポート属性を追加する必要があります。

RejseplanModuleは、タイプIModuleのエクスポートでマークされたMEFではありません。タイプミスかどうかを確認できますか?

外部DLL

[Export(typeof(IModule))]//<-- remove this if its handled by your custom ModulExport Attribute 
[ModuleExport(typeof(IModule), InitializationMode = InitializationMode.WhenAvailable)] 
class RejseplanModule : IModule, IPlugin 
{...} 

あなたのメインアプリ(上記fhnaseerからコード)

var directoryPath = "path to dll folder"; 
var asmCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); 
var directoryCatalog = new DirectoryCatalog(directoryPath, "*.dll"); 

var aggregateCatalog = new AggregateCatalog(); 
aggregateCatalog.Catalogs.Add(asmCatalog); 
aggregateCatalog.Catalogs.Add(directoryCatalog); 

var container = new CompositionContainer(aggregateCatalog); 

var allIModulPlugins = container.GetExports<IModule>(); 
:少なくとも、それは(typeof演算( はIModule)を参照)、以下の

EDITでなければなりません

+0

私は単にImoduleインターフェースのすべてのインスタンスを取得したい..しかし、私は[インポート]を使用しようとすると() - 何も起こらないので、私はインスタンスを取得しようとした.. –

+0

あなたのRejseplanモジュルはIModulタイプのエクスポート用にマークされていません – blindmeis

+0

これは動作しました!ありがとうございます:) –

0

これを行うようにしてください。

var directoryPath = "path to dll folder"; 
var asmCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); 
var directoryCatalog = new DirectoryCatalog(directoryPath, "*.dll"); 

var aggregateCatalog = new AggregateCatalog(); 
aggregateCatalog.Catalogs.Add(asmCatalog); 
aggregateCatalog.Catalogs.Add(directoryCatalog); 

var container = new CompositionContainer(aggregateCatalog); 

container.ComposeParts(this); 
+0

これは..私はwhenAvailableにinitmodeを設定しました - シェルが実行されているときにロードされますか? –

+0

初期化モードなしで実行してください。そんなことが起こる。 –

+0

同じことを私は恐れている:( –