1
votes

The basic idea that I'm trying to accomplish is to configure my Silverlight app to resolve its dependencies at runtime (without having to add references to dependent DLLs in the project).

I have my UI project that references an infrastructure project than contains various interfaces (e.g. repositories). Concrete implementations of these interfaces are stored in separate SL apps that I want to download and link to at runtime. I want to be able to configure my UI app from an external config file so that I can switch from one interface implementation to another at runtime without having to recompile the app.

What I have done so far is to create a Prism module for each implementation (in a separate SL app) and get those XAPs hosted in my web project. In my UI app I created a boostraper that has this:

protected override IModuleCatalog CreateModuleCatalog()
    {
        var mc = Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri("/UI;component/Repositories/ModulesCatalog.xaml", UriKind.Relative));
        return mc;
    }

ModulesCatalog.xaml looks like this:

<Modularity:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:sys="clr-namespace:System;assembly=mscorlib"
                      xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism">

    <Modularity:ModuleInfo Ref="ImplementationOne.xap"
                       ModuleName="ImplementationOne"
                       ModuleType="ImplementationOne.Module, ImplementationOne, Version=1.0.0.0" />

</Modularity:ModuleCatalog>

In my ConfigureContainer override I have:

protected override void ConfigureContainer()
    {
        var unity = Unity.CreateFromXaml(new Uri("/UI;component/Repositories/UnityConfiguration.xaml", UriKind.Relative));
        unity.Containers.Default.Configure(Container);
        Container.RegisterInstance<Unity>(Unity.ConfigurationKey, unity);

        base.ConfigureContainer();
    }

But the unity.Containers.Default.Configure(Container) throws that the assembly cannot be found. (If I manually add the DLL to UI.xap file this works so I guess I'm missing something as the XAP is either not being downloaded or the assembly is not getting registered).

I've been struggling with this for a week now, read lots of SO topics but still cannot solve the problem. All the examples that I have found contain direct project refrences which is exactly what I'm trying to avoid.

Thanks!

1

1 Answers

0
votes

To do assembly discovery and dynamic XAP loading you should use MEF container, not Unity.

See more information from official source: http://msdn.microsoft.com/en-us/library/ff921140(v=PandP.40).aspx