30

I downloaded Prism v4 and ran the installer. I went into the directory and ran the two following batch files:

  • Desktop only - Open Modularity With Mef QuickStart.bat
  • Desktop only - Open Modularity With Unity QuickStart.bat

When I compile these applications, I don't see any real difference. I've searched for MEF vs Unity and I've found some pros/cons, but nothing that specifically states whether one is "better" (and I know that is subjective) with use in Prism. I guess perhaps if I list my requirements someone can point me to the correct technologies to use (even if it's not Prism 4).

  • The application is to be written in WPF (NOT Silverlight).
  • The main application will be extremely thin.
  • The main application will use a Web Service to build the menu of the "apps/modules" a person has access to.
  • The "apps/modules" will be completely contained in other managed libraries.
  • The main application gets views and viewmodels by reflecting into these DLLs.
  • The main application should feed in services for logging, etc. into these "apps/modules".

For example:

A basic user might have the options of:

  • ViewOnly Address record

All items Address related are within Address.dll.

An advanced user might have the options of:

  • New Address record
  • Open Address record (update/delete)
  • Manage users

All items Address related are within Address.dll.
All items Manage related are within Admin.dll.

The app should not actually reference either of these DLLs, I plan to reflect into them so that if there are 100 different modules and a user only has access to 2 of them, only 2 of them are downloaded and used. Whereas a user that has access to 10 of them gets those 10.

I've already solved the downloading DLL via WebService. :)

myermian
  • 31,823
  • 24
  • 123
  • 215
  • Using 2.1 of Prism with Unity and WPF...been happy thus far, have not personally used MEF though... – Aaron McIver Dec 02 '10 at 21:52
  • What did you end up going with? I'm looking at a similar scoped project so your input would be great. – John Dec 08 '11 at 18:52
  • Thanks, do you have any input on how you did the privileges and downloading via service? Any input or tips would be great – John Dec 21 '11 at 19:17

4 Answers4

21

None is "better": they are different things.

IMO your choice should be driven only by your requirements. Based on the requirements you posted here I would suggest you to use MEF, because you have modules contained in DLLs and the main app is unaware of modules to load. Those tasks are the reason that why MEF exists.

Anyway you could use them both: MEF for modularity and Unity to take advantages of dependency injection (testability, reusability, ...)

onof
  • 17,167
  • 7
  • 49
  • 85
  • Do they place nice with each other or are here going to be some really bad growing pains as far as getting them to work together (MEF / Unity). – myermian Dec 03 '10 at 14:07
  • 10
    I work with them together. They are totally independent. The only pain is when you are designing something new and you have to state if it's an injectable dependency or an external component. But most of times is easy. – onof Dec 03 '10 at 14:44
  • 6
    Explaining my +1 on your comment: I like the **injectable dependency** vs **external component** phrasing to help distinguishing between what would be served by unity or mef. – odalet Feb 18 '11 at 16:56
4

If all the modules are not recompiled at the same time as the app, then MEF gives you lots of ways to cope with changing interfaces in the main app. Otherwise MEF may be more complex then you need.

Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317
2

I've been using Unity over a year with PRISM but I've noticed some serious memory leaking issues. Hence I decided to give PRISM 4 and MEF a go. What I've done is firstly converting my app to use PRISM 4 with Unity. Then I converted a branch to use MEF. It may sound funny but MEF seems to handle memory consumption and release somehow better than Unity.

Would be nice to hear whether others have made the same experience?

Michael Ulmann
  • 1,077
  • 5
  • 16
  • 9
    I can't understand why this answer has 3 +, with no comments. Either this has happened to other people (which is why they should +1 AND comment), or the memory leak is completely unrelated to Unity. I myself have never encountered anything like this. – Elad Katz Feb 19 '12 at 07:50
2

Regard to your question whether MEF and UNITY can work nicely with each other, i can tell you that they are working really well with each other. I have developed a proof of concept application which used PRISM, Unity and MEF.

myermian
  • 31,823
  • 24
  • 123
  • 215
Khoa
  • 33
  • 3