Print Page | Close Window

Cocktail 2012 - IWorkspace Why that change

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=3668
Printed Date: 10-May-2024 at 10:46pm


Topic: Cocktail 2012 - IWorkspace Why that change
Posted By: halloweenx8
Subject: Cocktail 2012 - IWorkspace Why that change
Date Posted: 26-Sep-2012 at 8:02am
Hi
 
I was using IWorkspace to dyamically create menu items after loading a XAP
 
       Composition.AddXapAsync("dymanicMenu.xap");
 
But it does not work anymore
 
Why the change to
         protected override void PrepareCompositionContainer(CompositionBatch batch)
        {
            base.PrepareCompositionContainer(batch);
            // Configure workspaces
            batch.AddExportedValue<IWorkspace>(
                new Workspace("Home", true, 0, typeof (HomeViewModel)));
            batch.AddExportedValue<IWorkspace>(
                new Workspace("Resource Management", false, 10, typeof (ResourceMgtViewModel)));
        }
How do you now dynamically add workspaces, in my case I adding a XAP with a workpace in it would have done the trick, how do I do that with Cocktail 2?
 
Thanks


-------------
Jean

"If You are Not Making Mistakes, then You are Not Doing Anything.”



Replies:
Posted By: mgood
Date Posted: 26-Sep-2012 at 12:02pm
You can still dynamically add workspaces, but IWorkspace is no longer automatically exported in TempHire. The change above is due to how the Navigator works in Cocktail 2. You no longer navigate to an instance of a ViewModel. You navigate to a ViewModel type.
 
So, therefore IWorkspace was changed to return the associated VM type for the navigator. Because I only have two workspaces in TempHire I decided to statically add them directly to the container instead of creating Workspace classes that are exported.
 
The workspace is basically just a lightweight proxy now that knows the type of the ViewModel that implements the actual workspace. The shell grabs the type from the Workspace and navigates to it, so the VM and all it's dependencies are not instantiate until you navigate to the workspace.
 
In your case you have to create a class for each workspace and export it as IWorkspace, so that it gets discovered when you load the xap.
 
So, for example I could have done the following instead of adding the home workspace via the CompositionBatch.
 
    [Export(typeof(IWorkspace))]
    public class HomeWorkspace : Workspace
    {
        public HomeWorkspace() : base("Home", true, 0, typeof (HomeViewModel))
        {
        }
    }

 




Print Page | Close Window