How to get a module instance in PRISM

只愿长相守 提交于 2019-12-10 21:17:11

问题


I have a PRISM desktop app which loads modules from a directory with the help of the DirectoryModuleCatalog.

Everything is fine, except that I cannot find a way to get the instance of a loaded module. IModuleManager and IModuleCatalog don't have a method like getInstance(ModuleInfo) or similar.

See

moduleManager.LoadModule(moduleInfo.ModuleName);

This line loads the module properly(moduleManager is of type IModuleManager), but what do I have to do next to get the actual instance of this module?

The modules are loaded on demand of the user, so I cannot register all modules at startup within the bootstrapper.


回答1:


If by Module instance you mean the class that implement IModule, then you must explicitly register the instance into the container to be able to get it.

Although the aforementioned will work, you should not take that approach at all. The idea is that the module classes are specific to a particular module and should only be used for module initialization purposes.

I would place each module's Start method in a separate component (IStartable), register each component in the container with a different Id and resolve/import an IEnumerable to get all instances that have the start method.

Hope this helps



来源:https://stackoverflow.com/questions/7887028/how-to-get-a-module-instance-in-prism

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!