MEF help /w CM

Topics: Bootstrappers & IoC
May 11, 2011 at 10:55 PM

So after trying to figure out why a property on my base class was not instantiated with the [Import] attribute on it I realized that unless I pull the whole object out of the MEF container which means I want to push everything into my container.  Here is the scenario I am trying to manage:

1 - Multiple workspace with a set of screens.  Each screen is sort of like a tab and has its own viewModel and it's own BO functionality. 

2 - Each workspace has some unique screens (WorkspaceAConfig, WorkspaceAStats) but also some shared screens that just load a different subset of data into the same viewModel (WorkspaceCommonPeople, WorkspaceCommonTowns). 

3 - Depending on the status of the data in a workspace it should only make available certain screens.  Ie) If the person details aren't set then you can't manage history or addresses etc.

Say I create a set of screens with the IScreenForWorkspaceA interface, and some screens with IScreenCommon

I'm a bit lost on how to either create my required views one at a time vs. ImportMany.  If I want to create them one at a time then do I need to explictly export everything as IScreenAForWorkspaceA, IScreenBForWorkspaceB and create them ?  If I do ImportMany how do I just get the ones I want when I only need 2 of 6 because my data isn't setup yet?  I don't want to instantiate anything I don't really need as my application is already a bit of a memory hog as it is.

I think I just need a methodology to follow or some help with how best to configure a LazyLoad...

I would like my screens to be smart enough that I just say -get everything a workspace might need, then each screen look at the master data and decide if you should intialize or just be an barely implement object.

Hopefully that makes sense?  My current non CM app is horrendous.  It spins up a 'workspace', creates everything, and then just shows what it needs.  It is a real mess in terms of efficiency and re-use.



May 12, 2011 at 12:22 AM

Mef has the notion of lazy imports and lazy collection imports. In addition to that, you can attach metadata to imports which you can query without instantiating the import. Perhaps this is what you want?

May 12, 2011 at 2:49 AM

Thanks - one quick google search on 'MEF lazy import metadata' and I'm set.

This, for anyone else that is interested, is exactly what I needed.

Once again thank you very much.