[Silverlight] MEF - avoid modules caching


When developing a MEF-based project there is always the problem to force the user to clear browser's cache to download newer XAPs. This may be not a problem to medium-skilled users, but for generic users it may be a problem. To avvoid this we can add a version number to the XAP name



In the Bootstrapper.cs class define the version property:

public string Version
{
    get { return System.Reflection.Assembly.GetExecutingAssembly().FullName.Split(',')[1].Replace("Version=", "").Trim(); }
}


And add the following highlighted part to the ModuleCatalog creation code:
protected override IModuleCatalog CreateModuleCatalog()
{
    IModuleCatalog catalog = Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri("/Shell;component/ModuleCatalog.xaml", UriKind.Relative));

  
    foreach
(var module in catalog.Modules)
       module.Ref += "?v=" + Version.Replace(".", "");
              
    return catalog;
}   

In the AssemblyInfo.cs of the Shell application (or whatever you called the parent XAP) you should set the build and/or the revision version number to *.
 
[assembly: AssemblyVersion("1.0.*")]
[
assembly: AssemblyFileVersion("1.0.*")]


Now when will require the XAPs, the browser will check the v=#### part of the name and, if it's newer than the cached one, will automatically download the new one without force the user to clear his browser's cache.

Commenti

Post più popolari