简体   繁体   English

具有安全性和配置文件效率的MEF插件

[英]MEF Plugins with Security and Profiles Efficency

I have an application that has many modules/plugins. 我有一个包含许多模块/插件的应用程序。 I am using MEF with a Directory plugin to import them. 我使用带有目录插件的MEF来导入它们。 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. 有一个概述区域,显示来自具有[ImportMany(typeof(IModule)]]属性的所有可见模块的信息。

What is a good way of handling this so that invisible or inaccessible modules are not created in memory. 有什么好的方法可以解决此问题,以便在内存中不创建不可见或不可访问的模块。

Lazy loading them will ensure they are not initialised or loaded into memory. 延迟加载它们将确保它们不会被初始化或加载到内存中。 Then use metadata to find the module names and details. 然后使用元数据查找模块名称和详细信息。

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. 使用[ImportMany(typeof(IModule)]将创建每个模块的实例,这就是MEF的工作方式,因此一种方法是让模块的构造函数不执行任何操作,然后在您所使用的每个模块上调用Load方法实际要使用,它可以完成所需的任何工作。

Alternatively, create a new interface called IModuleInfo which just has the information necessary for your overview area. 或者,创建一个名为IModuleInfo的新接口,该接口仅具有概述区域所需的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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