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