MEF Plugins with Security and Profiles Efficency

时光毁灭记忆、已成空白 提交于 2019-12-02 13:28:26

问题


I have an application that has many modules/plugins. I am using MEF with a Directory plugin to import them. Each user has a list of available modules stored in a database and each user can have multiple profiles controlling which modules are visible.

There is an overview area showing information from all visible modules with an [ImportMany(typeof(IModule)] attribute.

What is a good way of handling this so that invisible or inaccessible modules are not created in memory.


回答1:


Lazy loading them will ensure they are not initialised or loaded into memory. Then use metadata to find the module names and details.




回答2:


Using [ImportMany(typeof(IModule)] will create an instance of each module - that's just the way MEF works. So one approach would be for the constructors of your Modules to do nothing, and then call a Load method on each Module that you actually want to use, in which it can do whatever work it needs to do.

Alternatively, create a new interface called IModuleInfo which just has the information necessary for your overview area.



来源:https://stackoverflow.com/questions/5006332/mef-plugins-with-security-and-profiles-efficency

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