简体   繁体   中英

Unable to Initialise or load prism modules on demand

I want my modules to load on demand for that i have one confusion that if we are not going to initialise our modules initially then after load how and where we can write the code to execute and load the Module. For Reference what i have tried i am putting ShellViewModel code here only. Please let me know what else i need to do in order to load view on Demand or if you have any good demo reference please let me know

 public class ShellViewModel
    {

        public ShellViewModel(IModuleEnumerator moduleEnumerator, IModuleLoader moduleLoader, IRegionManager regionManager)
        {
            this.Initialize(moduleEnumerator, moduleLoader, regionManager);
        }

        public ICommand LoadModuleA { get; set; }

        public ICommand LoadModuleB { get; set; }

        public IModuleLoader ModuleLoader { get; set; }

        public IModuleEnumerator ModuleEnumerator { get; set; }

        public IRegionManager RegionManager { get; set; }

        private void Initialize(IModuleEnumerator moduleEnumerator, IModuleLoader moduleLoader, IRegionManager regionManager)
        {
            // Initialize command properties
            this.LoadModuleA = new LoadModuleACommand(this);
            this.LoadModuleB = new LoadModuleBCommand(this);

            // Initialize module properties
            this.ModuleEnumerator = moduleEnumerator;
            this.ModuleLoader = moduleLoader;
            this.RegionManager = regionManager;
        }

    }
}

Below is bootstraper class

public class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            var shell = Container.Resolve<Shell>();
            var shellViewModel = Container.Resolve<ShellViewModel>();
            shell.DataContext = shellViewModel;
            shell.Show();
            return shell;
        }

        protected override IModuleEnumerator GetModuleEnumerator()
        {
            return new DirectoryLookupModuleEnumerator(@".\Modules");
        }
    }

Please let me know if more code need to post i am unable to know how can load modules ondemand and where actual code need to write(ie in which section)

You don't use a directory module catalog for on-demand modules.

To load modules on demand, you need to specify that they should be loaded into the module catalog with the InitializationMode set to OnDemand. After you do that, you need to write the code in your application that requests the module be loaded.

A module is specified as on-demand using attributes, as shown in the following code example.

protected override void ConfigureModuleCatalog() { . . . Type moduleCType = typeof(ModuleC); this.ModuleCatalog.AddModule(new ModuleInfo() { ModuleName = moduleCType.Name, ModuleType = moduleCType.AssemblyQualifiedName, InitializationMode = InitializationMode.OnDemand }); . . . }

After a module is specified as on demand, the application can then ask the module to be loaded. The code that wants to initiate the loading needs to obtain a reference to the IModuleManager service registered with the container by the bootstrapper.

private void OnLoadModuleCClick(object sender, RoutedEventArgs e) { moduleManager.LoadModule("ModuleC"); }

You can read all about it in the docs: http://prismlibrary.github.io/docs/wpf/Modules.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM