Which DI framework to use?

Jan 28, 2010 at 9:18 PM

Hi all,

I am pretty much a newbie with regard to DI and I do see the advantages of using one.  Right now I am working on a SL3 app that I want to eventually host in the Azure cloud.  It has to be very flexible and this is where DI comes in.  I have been looking at Ninject for a number of reasons.  Lightweight, fast and the fact that you can configure it via code rather than using XML files.  Not that I do not like XML I can just see where this is a real plus.  However, being new to DI I think that there is more support for figuring out how Unity works vs Ninject.  That being said...

I have some questions -

Does Unity allow for configuration/wire up via code?  Does Unity allow support for contextual binding, in which a different implementation of a service will be injected based on the context in which it is requested?  How steep is the learning curve with Unity (I am an experienced software developer and have played around with some flavor of DI that was used with NHibernate about 2 years ago, although I just scratched the surface)?


Jan 29, 2010 at 1:49 AM

It turns out Unity is faster than Ninject at least last time I saw people do benchmarks. May have changed since that test was done, but we're certainly competitive.

Yes, Unity does allow for configuration via code. It's got a very flexible, extensible API for configuration. The Ninject-style contextual injection is unique to Ninject as far as I know, but it turns out you can accomplish the same results using named registrations.

As far as learning it goes, I'd suggest spending an hour with the Unity Hands-on-labs. That should give you all the background you need for a decision. It's written for the desktop version, but just about everything applies for the Silverlight version as well.

Hope this helps,