Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load Prism modules from dll files (at startup)

Atm in my application I do like this:

class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return Container.Resolve<Shell>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();

            App.Current.MainWindow = (Window)Shell;
            App.Current.MainWindow.Show();
        }     

        protected override void ConfigureModuleCatalog()
        {            
            base.ConfigureModuleCatalog();
            var moduleCatalog = (ModuleCatalog)ModuleCatalog;

            moduleCatalog.AddModule(typeof(FooModule));
            moduleCatalog.AddModule(typeof(BarModule));
        }        
    }

I would like to load FooModule and BarModule by indicating the path to the dll file, something like this:

protected override void ConfigureModuleCatalog()
{
...
            var assembly = Assembly.LoadFrom(@"libs\FooLib.dll");
            var type = assembly.GetType("FooLib.FooModule");
            moduleCatalog.AddModule(type);
...
}

but it doesn't work, I get this error message on Bootstrapper.Run() :

There is currently no moduleTypeLoader in the ModuleManager that can retrieve the specified module.

EDIT: this is my FooModule:

public class FooModule : IModule
    {
        private readonly IRegionViewRegistry _regionViewRegistry;

        public FooModule(IRegionViewRegistry registry)
        {
            _regionViewRegistry = registry;
        }

        public void Initialize()
        {
            _regionViewRegistry.RegisterViewWithRegion("MainRegion", typeof(Main));
        }
    }
like image 338
Omu Avatar asked Dec 29 '25 01:12

Omu


1 Answers

I think Prism v4 Loading modules on demand with DirectoryModuleCatalog could help.

UPDATE:
Sorry, just realized that reference mentioned above won't help.
Try this one from msdn - "Loading Modules on Demand" section, I think that's what you need.

like image 186
alex.b Avatar answered Dec 31 '25 17:12

alex.b