Migrating from MEF to Unity and Viceversa

Jul 17, 2012 at 4:22 PM

I'd like to know the necessary steps to migrate a project developed using MEF to Unity and viceversa.

I'm using Silverlight 5 and Prism 4.1.

Developer
Jul 18, 2012 at 5:34 PM

Hi,

As far as I know, there is no specific guidance with steps on how to migrate from one container to the other. As mentioned in this related thread by Michael Puleio, porting from one to the other shouldn't require much effort:

The development styles differ quite a bit due to the different approaches in design an scenarios for usage.  With MEF, it is recommended to do declarative programming (attributes for registration/exporting and importing).  With Unity, the more common approach is a lot more imperative (registration via code rather than attributes). Constructor injection is preferred in Unity (even though it can do property injection) vs property injection is preferred in MEF (even though it can do constructor injection).

The biggest challenge you will run into is the different styles, which I highlighted above.  Once you get past the style differences, it is a matter of ensuring all the types, services, etc get registered properly in the container, which requires deciphering a lot of very verbose error messages in exceptions.

In my opinion, as a starting point to achieve this, I believe you should consider the different specific capabilities of each container. You could find useful information about this in Chapter 3 of the Prism documentation.

Also, I believe the tips mentioned in this blog post could result useful:

Additionally, take into account that you could use the different examples provided along the Prism documentation, on how to achieve specific scenarios with each of the containers. For example I particularly believe that the following sections could result handy:

I hope you find this useful,

Agustin Adami
http://blogs.southworks.net/aadami

Jul 19, 2012 at 11:59 PM

Thank you Agustin. I'll check your info.