2011-07-10 34 views
0

我想用MEF來做到這一點,但也許我正在使用錯誤的技術。多個應用程序在一個'外殼'中工作

我有2個應用程序(現在都有更多的想法)一個是我轉換爲Silverlight的桌面應用程序。另一個只是一個適合相同結構的想法。我想將這兩個應用程序作爲獨立的自包含應用程序,並從一個shell站點運行它們。我一直試圖用MEF開始這個工作,但是我還沒有足夠的瞭解它,以便知道我做錯了什麼,或者它不是正確的技術。

目前我正在使用MVVM-light作爲我的框架,我已經取得了巨大的成功,現在我對它也很熟悉。我的每個應用程序都是獨立的...意味着我可以自己使用它們如果我將它們設置爲從我的Web服務器獨立運行。

問題出現在我嘗試使用mef將它們放入shell中時。

這是我的第一個modulecontainer代碼:

public partial class MEFDoctorsModuleContainer : Page, IPartImportsSatisfiedNotification 
    { 
     private System.Uri _requestedUri; 

     public MEFDoctorsModuleContainer() 
     { 
      InitializeComponent(); 

     } 

     [Import] 
     public IDeploymentCatalogService CatalogService { get; set; } 

     [ImportMany(AllowRecomposition = true)] 
     public Lazy<UserControl, IMetadataContent>[] MEFModuleList { get; set; } 

     // Executes when the user navigates to this page. 
     protected override void OnNavigatedTo(NavigationEventArgs e) 
     { 
      _requestedUri = e.Uri; 

      CompositionInitializer.SatisfyImports(this); 
     } 


     public void OnImportsSatisfied() 
     { 
      CatalogService.AddXap("WavelengthIS.Referee.PhysicianMaster.xap"); 

      //MEFModuleList.ToList() 
      //  .ForEach(module => 
      //  { 
      //   if ((module.Metadata.ContainerType == this.GetType().ToString() && 
      //    (module.Value.GetType().ToString() == "WavelengthIS.Referee.PhysicianMaster.MainPage.xaml"))) 
      //   { 
      //    content.Items.Add(module.Value); 
      //   } 
      //  }); 

      MEFModuleList.ToList() 
        .ForEach(delegate(Lazy<UserControl, IMetadataContent> module) 
          { 
           if ((module.Metadata.ContainerType == this.GetType().ToString() && (module.Value.GetType().ToString() == "WavelengthIS.Referee.PhysicianMaster.App.xaml"))) 
            content.Items.Add(module.Value); 
          }); 
     } 
    } 
} 

眼下XAP僅由一個項目,但最終還是會由我的數據,視圖模型和服務項目,爲客戶的。但即使如此,它崩潰了。它似乎並不喜歡viewmodellocator。

(module.Value.GetType().ToString() == "WavelengthIS.Referee.PhysicianMaster.App.xaml"))) 

用來等於這個

(module.Value.GetType().ToString() == "WavelengthIS.Referee.PhysicianMaster.MainPage.xaml"))) 

但我在想,這難道不工作,因爲我其實導入一個應用程序,而不僅僅是一個頁面。

所以我的問題是這樣的:鑑於我正在嘗試做什麼是使我的工作最好的選擇?

我並沒有停留在MEF上,但是我確實需要一個使用SL4中的導航框架將獨立程序加載到其中的Shell應用程序。我需要MVVM-Light的工作原理,因爲我很喜歡這個框架,儘管我沒有寫MVVM Enterprise應用程序,但我更喜歡將它放在我的竅門中。我不喜歡hocus pocus ...國際奧委會和依賴注入不在桌面上,因爲我不習慣使用該技術,如果我需要使用它,我會找到其他方法來做到這一點。

回答

相關問題