Print Page | Close Window

Dynamic load workspaces

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3712
Printed Date: 27-Mar-2025 at 7:26pm


Topic: Dynamic load workspaces
Posted By: Peter
Subject: Dynamic load workspaces
Date Posted: 12-Oct-2012 at 6:14am
Hello Cocktail colleague's,
 
I’m writing my first cocktail Silverlight (SL5) application en getting familiair with MEF.
So, I’m new to this.

I’m trying to dynamically load a IWorkspace ViewModel from a separate XAP file. I’m using the example found in the documentation.
On the main SL application (the one loading a SSHBizzOrganisation module) I have the following code.
Basically copied from the example.
 

[Import("MainViewModel", AllowRecomposition = true, AllowDefault = true)]
public ExportFactory<IWorkspace> OrganisationModuleFactory { get; set; }
 
private IEnumerable<INotifyCompleted> ShowOrderDetail(OrganisationModuleMessage message) {
// Let's make sure the xap that contains the OrderEditor is loaded.
// Only the first call will load the xap, subsequent calls don't do anything.
yield return Composition.AddXapAsync("SSHBizzOrganisation.SL.xap");
// Now we can access the OrderEditorFactory. MEF recomposed this instance
// and provided us with an OrderEditorFactory.
var editor = OrganisationModuleFactory.CreateExport().Value;
var handler = editor as IHandle<OrganisationModuleMessage>;
if(handler != null) handler.Handle(message);
}
 
When I run this, the AddXapAsync(..) call is working fine.
But the ‘OrganisationModuleFactory’ property is always null.
I’m sure I forgetting something here of within the module implementation.
The SSHBizzOrganisation module looks like this:
 

namespace SSHBizzOrganisation.ViewModels
{
[Export(typeof(IWorkspace))]
public class MainViewModel : Screen, IWorkspace, IDiscoverableViewModel
{
public MainViewModel()
{ // ReSharper disable DoNotCallOverridableMethodsInConstructor
DisplayName = "Desktop";
// ReSharper restore DoNotCallOverridableMethodsInConstructor
}
 
I have read some of the forum posts, but I probably missing some basic understanding.
It’s not clear to me if I should use the PartFactory implementation or just use the [Export] attribute like I’ve done above.
I have tried both.
 
Hope some can point me in the right direction.
Peter
 




Replies:
Posted By: mgood
Date Posted: 12-Oct-2012 at 11:55am
Peter,
Your code above is looking for an export named "MainViewModel" and type IWorkspace. That doesn't match the ExportAttribute you have on your ViewModel. It should be like this:
 
[Export("MainViewModel", typeof(IWorkspace)]


Posted By: Peter
Date Posted: 13-Oct-2012 at 5:37am
Thank you Marcel,
 
Sounds logical.
I've added the following within the module.
[Export("MainViewModel", typeof(IWorkspace))]
public class MainViewModel : Screen, IWorkspace, IDiscoverableViewModel
{
 
But, OrganisationModuleFactory property is still throws a null exception. 
Is there a complete example so I can compare my module.
I believe I'm forgetting something within my module implementation. 
 
Again, thank for your help.
 
Peter


Posted By: mgood
Date Posted: 13-Oct-2012 at 11:44am
Here's an example I wrote a while back for a customer in Germany, so it's got some German comments in there. It's SL4, but I just updated it to the latest version of Cocktail.

uploads/1005/ApplicationStarter.zip - uploads/1005/ApplicationStarter.zip



Print Page | Close Window