Reputation: 2423
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.
Upvotes: 1
Views: 816
Reputation: 8196
Lazy loading them will ensure they are not initialised or loaded into memory. Then use metadata to find the module names and details.
Upvotes: 2
Reputation: 49522
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.
Upvotes: -1