Print Page | Close Window

Moving to dynamic module loading

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=3508
Printed Date: 01-Apr-2025 at 11:52pm


Topic: Moving to dynamic module loading
Posted By: pponzano
Subject: Moving to dynamic module loading
Date Posted: 26-Jun-2012 at 2:20am
Hello,
sorry to disturb you again, i've got a SL 5 application that's composed of modules but currently they're all loaded when the application starts (I've added them as reference to my sl application).

I've read http://drc.ideablade.com/xwiki/bin/view/Documentation/cocktail-dynamic-xap - this post on the wiki but I've no clear idea on where to put this... another client requisite (if possible) is to load the module only if the user is allowed to (I've  a core module that will be loaded (and referenced) by different projects), considering that I know if a user can/can't load that module if it's defined a role for it (asp.net role) what 's the best approach for my needs?

I've also checked the TempHire demo but it doesn't use Composition.AddXap...  can someone help me on this?
Thanks



Replies:
Posted By: mgood
Date Posted: 26-Jun-2012 at 9:00am
There are generally two approaches. You can eager load the Xap files during the bootstrapping of the application or in your case after the login, since you need the user's roles, or lazy loading the Xap file when the user first tries to enter a certain module.
 
It sounds like the best approach for you is to load them after the login. Similarly to TempHire, where it pre-loads some data using the PreLoader, you can have a coroutine at that point with a number of Compositon.AddXap calls that load the appropriate modules based on the user's roles. You can use a parallel coroutine to load them in parallel.
 
On a side-note I'm going to rename Composition.AddXap to Composition.AddXapAsync. Just noticed that I forgot to add the Async postfix to this method.


Posted By: pponzano
Date Posted: 26-Jun-2012 at 9:12am
Hello Marcel,
I was of the same mind of you, after the login I've created a
 

[Export(typeof(IPartFactory<MenuViewModel>))]

   public class MenuViewModelFactory : PartFactoryBase<MenuViewModel>

   {

   }

and on the Execute method I do
 

public void Execute(ActionExecutionContext context)

      {

          IList<string> rolesList = userService.CurrentUser.Roles;

 

          var filtered = rolesList.Where(o1 => o1.StartsWith("module"));

 

          if (filtered.Any())

          {

             // Here I have to download the modules  

          }

       //   GetMenuItems();

      }

I think I'll need to store some information on the DB for telling my app to download for module_admin the full path to the admin's module... what you think about this?
 
Or if there was a DirectoryCatalog equivent I would have download the list index and parsed it ...
Is this approach ok?


Posted By: mgood
Date Posted: 26-Jun-2012 at 9:20am
Yes, that's correct. You need to store some metadata about your modules somewhere, either in the DB or an XML file on the server that you can download. 

Your code won't quite work. Keep in mind AddXap is an asynchronous operation. You need to wait for it to finish before you can access anything from the downloaded Xap file.


Posted By: pponzano
Date Posted: 26-Jun-2012 at 12:26pm
I know I know.... I'll use a Coroutine.BeginExecute to wait the data...or am I wrong?


Posted By: mgood
Date Posted: 26-Jun-2012 at 1:03pm
Yes, that works.


Posted By: pponzano
Date Posted: 26-Jun-2012 at 11:47pm
It's morning in Italy and I've a question for you.........currently my solution's module are .dll, since I have to load XAP file, have I to re-create my projects as Silverlight Application? what about their own bootstrapper? should I implement them?
 
Thanks


Posted By: mgood
Date Posted: 26-Jun-2012 at 11:56pm
Yes, in order to get a XAP file you need to create them as Silverlight Applications, but they don't need a bootstrapper.



Print Page | Close Window