need advise on architecture

Jan 18, 2011 at 6:32 PM

Hi guys.

What is proper way of designing of SL system if components are different applications? Well, easier to show than explain.

Application_A  //has reference to Application_Interfaces.dll

{ [Export(IApplication_A)] MainForm_A_UserControl.xaml <Resources>MainForm_A_UserControl_VM<Resources/> <button Content="Load dependency service" command={LoadServiceOnDemand()}/> MainForm_A_UserControl_VM { DeploymentCatalog dc = new DeploymentCatalog("service.xap"); [Import(typeof(IService), AllowRecomposition=true,AllowDefault=true)] IService Service{get;set;} public void MainForm_A_UserControl_VM() { CompositionHost.Initialize(dc); CompositionInitializer.SatisfyImports(this); } void LoadServiceOnDemand() { dc.downloadAsync(); } } } Application_B //Published somewhere and developed by another team, has reference to Application_Interfaces.dll { [Export(IApplication_B)] MainForm_B_UserControl.xaml <Resources>MainForm_B_UserControl_VM<Resources/> <contentControl Tag="Place for application_A" Content={Binding Application_A}/> MainForm_B_UserControl_VM { [Import(typeof(IApplicationA),AllowRecomposition=true,AllowDefault=true)] IApplication_B Application_A {get;set;} public void MainForm_B_UserControl_VM() { deploymentCatalog = new DownloadCatalog("url of published application A.xap"); } void Load_Aplication_A(){ deploymentCatalog.downloadAsync(); } } }
Application_Interfaces
{
	interface IApplication_A{}
	interface IApplication_B{}
	interface IService{}
}
So in psevdo code above I am injecting application A into application B and show it in ContentControl. 
Now I see application_A GUI. I click button (aka call Application_A.LoadServiceOnDemand()), and expect application_A start downloading it`s dependency to satisfy IService Service{get;set;}.. 
But get exception: A first chance exception of type 'System.InvalidOperationException' occurred in System.ComponentModel.Composition.Initialization Additional information: The container has already been initialized either by another call to InitializeContainer or by someone causing the default container to be constructed. Ensure that InitializeContainer is one of the first things that happens in the application host to ensure that it is ready for the first composition. 
So I understand that Mef don't like that I initialize Container in 2 places - in Application_B and in Application_A...
But this is how my application_A is designed, it must do it`a job and application_B shouldn't care how application_A works.....
How properly design this application relationship?