您可能會過度複雜化使用MEF和外部進口。通常會發生的事情是,您的應用程序中有您的正常項目依賴關係或外部依賴項,並且從我的帖子中可以看到,到目前爲止您的工作狀況良好。
當您將MEF添加到等式中時,您的問題就出現了。這可能是因爲您引導MEF並導入這些DLL的方式,而且我無法通過查看代碼來找到它。
我可以告訴你我是怎麼做的,有sucess,在應用程序我開發:
我安裝一切正常,與我需要對每一個項目,然後當我自舉MEF正常項目的依賴,從主要的WPF應用程序項目,其中有幾乎所有引用(在我的特定情況下,它是從棱鏡MefBootstrapper)我只是做的是:
public class SigepBootstrapper : MefBootstrapper
{
protected override void ConfigureAggregateCatalog()
{
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SigepBootstrapper).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(AutoPopulateExportedViewsBehavior).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StatusBarView).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Traversals).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(EngineManager).Assembly));
}
...
如果我不使用棱鏡我會創造AssemblyCatalog無論如何,只是將它們設置成不同的方式,所以沿着其他一些引導程序,我會繼續沿着lin寫es的:
new AssemblyCatalog(typeof(SigepBootstrapper).Assembly)
好的......想通了。我需要將xaml文件的BuildAction設置爲Page,而不是Content。大新!即與MEF完全無關。 – 2011-04-21 11:11:54