Intercept part construction for DynamicProxy

Jun 20, 2011 at 10:50 AM

I would like to intercept part construction in MEF in order to add functionality to the constructed objects.

e.g. If I wanted to give INotifyPropertychanged functionality to a ViewModel in a WPF application, I could use Castle DynamicProxy as described in this article: http://www.codewrecks.com/blog/index.php/2008/08/04/implement-inotifypropertychanged-with-castledynamicproxy/

I have seen that the MEFContrib project gives object interception, but this doesn't appear to work correctly (at least for my purposes) - it constructs the object for you and then gives you the ability to intercept the constructed object before it is returned by MEF. Ideally, I would want the ability to intercept before object construction and be given the type to be constructed as well as initialised constructor arguments (e.g. if it is an importing constructor I need these to be constructed by MEF). I could then intercept at this point, construct the object with a dynamic proxy and pass back to MEF where it would take care of "Satisfying" the other imports (property imports).

I have managed to sort out the first part of this (as described in my reply to this post to someone doing the same thing and asking the same question: http://mefcontrib.codeplex.com/discussions/261642 ), but I am unsure about how to SatisfyImports after object construction (and I am also not happy with the way I get the object type from the ExportDefinition before interception).

There hasn't been much activity in the MEFContrib forums so I though I would raise this issue here as well to see if anyone had any ideas.