New Posts New Posts RSS Feed: Dynamic load workspaces
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Dynamic load workspaces

 Post Reply Post Reply
Author
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Topic: Dynamic load workspaces
    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.

Back to Top
Peter View Drop Down
Newbie
Newbie


Joined: 14-Jun-2010
Posts: 7
Post Options Post Options   Quote Peter Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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)]
Back to Top
Peter View Drop Down
Newbie
Newbie


Joined: 14-Jun-2010
Posts: 7
Post Options Post Options   Quote Peter Quote  Post ReplyReply Direct Link To This Post 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
 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down