25
votes

I'm using the Unity IoC container. It really wasn't a decision I made, it just came with Prism, and I've just stuck with it. I've never used any other IoC frameworks, and I must admit I'm quite happy with Unity. However, the satisfaction may come from ignorance as I don't really know what the other frameworks have got to offer.

I keep hearing that I shouldn't use the Unity IoC container. "Use Castle, nInject or StructureMap instead", people are saying, but I still haven't heard any concrete arguments or examples to why I should use a different framework. So, why shouldn't I use Unity? Or maybe I should?

2
The accepted answer to this stackoverflow question (stackoverflow.com/questions/411660/…) became a really detailed blog post (here, elegantcode.com/2009/01/07/ioc-libraries-compared) that may be helpful.Jeff Sternal
Indeed very useful! I've somehow missed this question when looking for existing ones on the subject. Thanks!stiank81

2 Answers

14
votes

These containers tend to be about taste, more than anything. Ninject has a nice fluent interface for configuring it, but some people like Unity's ability to be configured through config (masochists, I think) as well as code.

I, like you, had these questions when adopting Prism, so I went through the exercise of replacing Unity with both Ninject and Autofac. I found no compelling reason in terms of performance or features to stick with either over Unity. There are certain things that were nice in both, but they all did basically the same thing and did it well.

I would look at the features, style, and syntax of each and decide which one you like best. That's really the only difference... how it feels. There are generally some core feature differences, but the likelihood of you needing these is pretty slim.

Post an update about what you decide... I'm always interested in people's real world findings vs. what passionate users are advocating.

12
votes

One reason to use Unity is if you're needing to work in a medium trust environment. From what I've found, Unity seems much easier to get running if your code doesn't have full trust. I've used a few IoC containers and I use Unity when I need medium trust.