Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Silverlight TV 11: Dynamically Loading XAPs with MEF

Download

Right click “Save as…”

Glenn Block, Program Manager working on MEF and self professed "MEF Maniac," makes a return visit to Silverlight TV. Glenn dives right into the code and shows how to use MEF to load and unload XAP files on demand. This is a great way to solve the problem of how to handle large applications in Silverlight with large XAP files.

All code samples from the episode can be found via this link.

Follow @SilverlightTV on Twitter for the latest updates.

Tags:

Follow the Discussion

  • You guys Rock! This is such a clean solution for developing large app.

    John, seriously you and Glenn should write a book on "Building large app with MEF & SL". I love the way John always stops at the right point to clear certain points. He did that in his book too.

  • Why is SL application split to XAPs. Why not split to DLL (one XAP shell and many DLL to download).

    Split to DLL will be more "compatible and smooth" if you have single source code for SL and WPF application.

     

  • john what's in that koozie?

     

    Having this flexibility will allow for more sophisticated applicaitons while maintaining a positive user experience by delivering functionality on demand.

     

    Thanks for the video, glad to know this is on the road map.

  • >>john what's in that koozie?<<

     

    Looks like a Bud can to me! Smiley

  • John Papajopapa Evangelist on the Loose

    Having separate XAPs allows you to keep the proejcts completely decoupled perhaps to build them at different times without affecting each other (just one possibility). Another option is when you have one team building an architecture while another team or company builds a plug in for your architecture. The disconnected XAPs is a more elegant solution in many ways than separate DLLs as it gives you more opportunity to keep your code fully decoupled.

  • John Papajopapa Evangelist on the Loose

    Ben & zenbeats - I'm not telling what's in the koozie Smiley

  • Well, it's a white Can,

    you're smiling in that shot (looks like you're feeling good)

    and you're hanging on to table table pretty tightly,

    I'll say it's a Cold one.


    “if it looks like a duck and sounds like a duck, it’s probably a duck” Tongue Out

  • Cesnek


    XAPs provide a way to groups of related functionality into a simple deployment unit.  Without such a unit you have to manage all dependencies at a very fine-grained level.

     

    Glenn

  • Thanks Ben. We are currently planning a MEF book, we'll have to see if John is interested in authoring a chapter or two.

     

    Glenn

  • Ran into an issue with composition happening more than once for a given element and that's because I was using page navigation and if the user navigated to a page, navigated away and then return to page, I was trying to load xap again.  So what I did is made a change to the AddXap method to check if the aggregateCatalog already contains the deploymentCatalog

     

     

    public void AddXap(string uri)

    {

        DeploymentCatalog catalog;

        if (!_catalogs.TryGetValue(uri, out catalog))

        {

            catalog = new DeploymentCatalog(uri);

            catalog.DownloadAsync();

            _catalogs[uri] = catalog;

        }

        if (!_aggregateCatalog.Catalogs.Contains(catalog))

        {

            _aggregateCatalog.Catalogs.Add(catalog);

        }

    }

     

  • John, Glenn

     

    Thanks for the great post, helped me get my head round a few issues concerning MEF!

     

    I have a question tho, is it possible to have an independant navigation framework working in one or more of the child XAPs and import the required navigation elements into the host XAP to navigate to said child XAP?

     

    Sorry if this is confusing, we are considering using MEF for a couple of large projects we're about to start and this is one of the requirements.

     

    If more info about the projects would help you answer the question please feel free to contact me directly.

     

    Kind regards,

     

    Jonny

  • Hi Jonny

     

    It is possible to integrate MEF with Navigation in SL4 and even to navigate cross-xaps. I demo that in my recent MIX talk which the code that I demo is also available. I posted a link to the code in the comments.

     

    The session is here: http://live.visitmix.com/MIX10/Sessions/CL52

  • I would like to know following

    - Does MEF support dynamic XAP loading of two Silverlight Application where one has  "windowless" parameter set to true and

      another with "windowless" parameter as false.

    I have situation where I have to use Silverlight DataForms to enter Japanese Characters (IME support) and I also have HTML content to be displayed.

    For HTML content - windowless parameter needs to be true and for IME support the windowless parameter should be false.

    So, application using HTML content and IME characters cannot co-exist in a single XAP.

    Any insight to above issue will be appreciated.

     

    sdeepak

  • I don't see why it wouldn't work as the DeploymentCatalog does not have any UI dependencies. Haven't tried it though Smiley

  • Mike Grahammgraham Mike Graham

    All of this is AWESOME...

     

    Question: is there a way to avoid downloading assemblies that are already included in the base XAP or in one of the dynamically downloaded XAPs?

     

    Related Question: can I now (in Silverlight 4) enumerate the assemblies that an assembly references?

  • Mike Grahammgraham Mike Graham

    Here is an excellent description of the deployment catalog including information on how to create a XAP that references assemblies, but does not include them (copy local = false).

     

    http://mef.codeplex.com/wikipage?title=DeploymentCatalog&referringTitle=Using%20Catalogs

     

    The main caveat is that a XAP that does include these assemblies must already be loaded before loading such a XAP (otherwise when MEF enumerates the contained types, Silverlight will throw an exception about the assembly or referenced assemblies not being loaded).

  • Any chance of getting the sample code in VB?

     

    I am failing to get it a C# conversion that works.

     

    Thanks

  • CeyhunCeyhun Ceyhun Ciper

    Hi Glenn,

     

    All of that is absolutely fantastic and I am trying to leverage every part of it (especially the DeploymentCatalogService approach, although I fear (and hope) that it will be overridden with a true distributable in the near future).

     

    However, these samples are a little bit misleading; SatisfyImports() is not asynchronous and you have already loaded all the catalogs before the button is pressed; if you put AddXap() to the button click nothing will work; and this is exacly the scenario that we want: nothing should be pre-loaded unless it is going to be used. Essentially, you pre-load everything in the main page and if the user quick enough and the server slow enough it will break as well.

     

    In short I would expect IPartImportsSatisfiedNotification to be more closely related to an async SatisfyImports.

     

    Regards,
    Ceyhun

  • syed ijlal haider 15606syed ijlal haider 15606

    Here is an excellent description of the deployment catalog including information on how to create a XAP. thanks
       url:  http://www.livetv.pk
    id: 15606

  • Muhammad ArslanMuhammad Arslan

    thanks for giving nice website

  • good !!!

  • I have one some questions Glenn would you please be able to answer!

     If i create different class libraries in my  single silverlight application, means there is only one xap and in my SL application i am importing controls from other library projects , so what is the benefit ? because the xap is downloaded at client at srartup so how can i say its a dynamic loading .

    In multiple xap project i can understand becasue control referenced in the other xap is loaded dynamically at the moment when i need that control .

    Regards.

     

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.