My application is comprised of a few core assemblies and several extension/plugin assemblies. In order for MEF to know all the parts the plugins have to offer, I have to load these assemblies even if I'm never going to use any of their parts. This makes the application take more time to start (if I'm going to load all the assemblies on startup) and also increases the memory footprint.
Ideally, I won't have to load the assemblies until I actually need them. I would load only the plugins' export data, and when I actually need to import a part, MEF would load the assembly and provide the part.
I found that there is something that does pretty much everything I just wrote, but after asking about it in MEF CachedAssemblyCatalog - Lazy Loading of Assemblies, I realized this code isn't considered stable and is not being maintained by the MEF team, so I've decided not to use it.
My question is how then can I achieve this behavior:
- Being able to access plugin assemblies' export metadata without loading their entire assembly.
- Transparent integration with the code importing the parts; i.e. use imports as usual - someone else (a specialized catalog?) will take care of loading the assemblies if necessary and provide the requested part.
- Not losing any existing MEF functionality such as recomposition, lazy types, etc.
I'm completely fine with a solution that requires parsing the plugins in advance to create a metadata assembly, XML file or whatnot.