using child containers when you use shared and non shared Creation Policies with MEF?

Jan 11, 2012 at 4:24 PM

So I ran into an issue where a long running process I have was growing quite large in memory. And after getting a stackdump and looking through the heaps I noticed the compositioncontainer I am using was getting rather large. I'm using a static container and I thought all my compositions were marked as shared but alas I might have missed a few...

But this led me to research how this relationship between shared and nonshared should be handled and I noticed that for nonshared a lot of times people use a child container to satisfy imports and then dispose so that it doesn't grow large.. So I went down this path and found this handy fellow
http://mef.codeplex.com/wikipage?title=Filtering%20Catalogs

to create filtered catalogs based on shared and nonshared exports...

The problem I'm having though is that I get a rejection exception with Satisfying the imports on an object that has a Shared import... so if I do

NonSharedChildContainer.SatisfyImportsOnce(someObject)

I get a rejection exception because there's a property in there that has a shared import on it... It seems like if you have an object that contains a shared import and non shared import there's not really a way to do composition in this format with a child container?

The only things I've figured out to do are
1) Go through my code and use GetExport instead of satisfyimports
2) I might be overloading MEF cause I'm kind of using it as our IoC container and I know there's always been lots of discussion around that... So it might be better to just use Unity or something like that