This post is about using MEF in Silverlight, and specifically getting going using the quick starts in the Prism (4.1 in my case) download.
I’ve mentioned the Prism Developer’s Guide. For MEF and Silverlight it points you to the .bat highlighted below, which just starts up that solution.
I’m using Visual Studio 2012, whereas the Prism 4.1 Quickstarts assume VS2010. Hence I get a bunch of upgrade alerts:
Nothing to worry about, as it all compiles and runs fine:
Browsing through the code, we see that, in places anyway, the Quickstart has implemented its own INPC, rather than just using the Prism version:
If I remove the System.ComponentModel using, to force the issue, then we can see where we need to update things:
We replace INPC with NotificationObject from the Prism Libraries:
This then prompts us with the new Using:
I made the mistake on redoing this of looking for a specific Prism ViewModel DLL on the file system. Doh. You just want the general, Silverlight specific, Prism DLL:
With that in place, we can now just remove the helper event handler and method.
Also remove the string constants, as we’ll be replacing these with lambdas:
Now we have broken stuff…
… until we make the change to a lamdba (a minor performance overhead, as everyone notes):
, and then generally tidy up:
Finally make sure it still all runs (you’ll just have to take my word this is a fresh screenshot):
quod erat demonstrandum, as we used to say, when I was a boy.