Prism v4: Unity or MEF?
Asked Answered
S

4

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. :)

Sorb answered 2/12, 2010 at 21:43 Comment(3)
Using 2.1 of Prism with Unity and WPF...been happy thus far, have not personally used MEF though...Homograph
What did you end up going with? I'm looking at a similar scoped project so your input would be great.Cockroach
Thanks, do you have any input on how you did the privileges and downloading via service? Any input or tips would be greatCockroach
J
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, ...)

Jiminez answered 3/12, 2010 at 7:55 Comment(3)
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).Sorb
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.Jiminez
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.Robalo
P
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.

Pfeffer answered 3/12, 2010 at 10:29 Comment(0)
J
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?

Joliejoliet answered 12/2, 2011 at 0:23 Comment(1)
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.Darcidarcia
S
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.

Sternwheeler answered 30/6, 2011 at 22:37 Comment(1)
Could you share that application with us?Cockroach

© 2022 - 2024 — McMap. All rights reserved.