Lazy load of assemblies (plugins) in MEF

Nov 23, 2011 at 8:51 AM
Edited Nov 23, 2011 at 1:42 PM

My question is if its possible to create MEF application so that addins (assemblies with MEF Exports - parts) are loaded on demand - immediatelly before using the part/instance (NOT when you call CompositionContainer constructor)?

Actually I want obvious thing: optimize both memory usage and startup load time for my application composed of many services/MEF parts. And though MEF seems perfect for addins, I see the disadvantage: all parts are loaded on application startup (when I call CompositionContainer with DirectoryCatalog). So, even if I do not use some given part yet, the appropriate assembly is already loaded. I want it to be loaded only when I really use this part, immediately before it's instantiation.

It seems that I need some kind of caching of metainformation here. Does MEF support this feature now out of the box?

 

Thanks,

Alex

 

Nov 23, 2011 at 3:47 PM

Hi Alex,

This isn’t available out-of-the-box today; it can be achieved with a custom catalog but the work involved is significant.

Regards,
Nick

From: AlexPetrov [email removed]
Sent: Wednesday, November 23, 2011 12:51 AM
To: Nicholas Blumhardt
Subject: Lazy load of assemblies (plugins) in MEF [MEF:280528]

From: AlexPetrov

My question is if its possible to create MEF application so that addins (assemblies with MEF Exports - parts) are loaded on demand (NOT when you one calls CompositionContainer constructor)?

Actually I want obvious thing: optimize both memory usage and startup load time for my application composed of many services/MEF parts. And though MEF seems perfect for addins, I see the disadvantage: all parts are loaded on application startup (when I call CompositionContainer with DirectoryCatalog). So, even if I do not use some given part yet, the appropriate assembly is already loaded. I want it to be loaded only when I really use this part, immediately before it's instantiation.

It seems that I need some kind of caching of metainformation here. Does MEF support this feature now out of the box?

Thanks,

Alex