views:

158

answers:

1

Now that I'm working on my newer application that uses MEF with the MVVM light toolkit, I've run into a case where I can't load specific plugins because they rely on a part that isn't getting exported. That part isn't getting exported because it's a View, and the View isn't resolved with MEF (yet).

It seems that every time I play with MEF, I need to move the part composition step (i.e. create container, catalog, then compose parts) closer and closer to the main application. I believe that I am now at that point. However, the problem is that I'm not sure exactly where to put it.

I'd like to put it MainWindow, which I believe is created by the MVVM light tookit project template. I have used the Export attribute on MainViewModel and Model. I am importing the ViewModel in the ViewModelLocator, and I import the Model in the ViewModel. To me, this seems like enough to ensure that everything gets composed properly. However, while the ViewModel is composed properly (it hits its constructor), the Model is not. I checked the output window during composition, and I don't get any MEF errors there.

So in summary, these are my issues: 1. Where is the "right" place to compose parts? In the WPF / MVVM case, would it always be at the start of the app? 2. In the absence of MEF errors in the output window, what are other techniques to figure out why things aren't getting resolved? Normally, I will step all the way through Compose to try to get some insight. Are there better debugging techniques than this? 3. Can you think of why my Model wouldn't get loaded? 4. Are there good MEF + MVVM light toolkit projects I can download to study?

A: 

Just use MEFedMVVM and you will not have any of these problems. As the name suggests it has been build from the ground up to solve the type of issues that you are mentioning. And it has a lot more precious features for building mvvm apps. Good luck.

Przemek
Thanks for the tip, I hadn't heard of MEFedMVVM. I'll check it out.
Dave
I'll keep reading up on it, but since it's only been tested with .NET 4.0, I will wait until I can upgrade to VS2010.
Dave
You can use MEF and MVVM in VS2008.
Rick Ratayczak
@Rick: I'm using MEF and MVVM in VS2008, but I was just saying that the Codeplex project MEFedMVVM claims to only be tested under VS2010.
Dave
@Dave api wise, it's pretty much the same. just different file references.
Rick Ratayczak
@Rick thanks, I'll take a look at it when the need arises again. I'm in that "need to get everything done now" mode at the moment. :)
Dave