2

Possible Duplicate:
Which .NET Dependency Injection frameworks are worth looking into?

Hi,

As a new kid in the C#/.NET block just moved in from Java neighbourhood, I am looking for options in Dependency Injection/IoC frameworks for .NET/C#.

From Scott Hanselman's blog post few years ago I got a fairly long list of DI frameworks, but there was really not enough information to go with beyond the list itself (plus a license and a version number) to make any semi-intelligent choice. Nor have I developed a ghestalt of the relative popularity (and thus the community support available) for any of these. And the list itself dates from 2008, which makes it a bit outdated, so I would like to ask kindly SO community for help on this matter.

Please list (or vote for) your favourite DI framework, adding a link to framework official website and please be so kind as to provide some reasoning for helping me and others developers like me to make a choice.

A code sample snippets for declaring and injecting dependencies would be of great help as well.

NB: Please restrict yourselves to one entry per response please, to keep it simple and objective.

Community
  • 1
  • 1
Roland Tepp
  • 8,301
  • 11
  • 55
  • 73
  • 2
    This surely have been discussed here at SO previously: http://stackoverflow.com/questions/21288/which-net-dependency-injection-frameworks-are-worth-looking-into and http://stackoverflow.com/questions/4581791/how-do-the-major-c-di-ioc-frameworks-compare – Peter Lillevold Feb 28 '11 at 09:51
  • 1
    `Please restrict yourselves to one entry per response please, to keep it simple and objective` How can it be objective when everyone vote on their favorite container? – jgauffin Feb 28 '11 at 11:21
  • @jgauffin: by "objective" I meant that the results of such "voting" would very likely reflect relative popularity and mindshare of projects in question... Bun nevermind, as this question was closed as duplicate.... – Roland Tepp Feb 28 '11 at 15:10
  • Yes, but everyone would still vote on their favorite framework. There are no correct answers, just subjective ones. – jgauffin Feb 28 '11 at 17:01
  • @jgauffin it's simple statistics - given enough subjective opinions, trends start to emerge that are as objective as such can be. – Roland Tepp Mar 01 '11 at 09:18

4 Answers4

2

I have used Ninject before and got on well with it. There are code samples on the front page of the website.

http://ninject.org/

Edit: Ninject also supports MVC

WraithNath
  • 17,658
  • 10
  • 55
  • 82
1

Of those I have tried, I like Unity best by far. Easy to use, and feature rich. A note is that it's not supported if you are developing for Windows Phone 7.

Øyvind Bråthen
  • 59,338
  • 27
  • 124
  • 151
1

Of the list I've tried Unity, StructureMap and Autofac.

I perfer StructureMap, I think it's the most straightforward and easiest to use. (didn't spend much time with Autofac tho since was just messing in my own time)

Phill
  • 18,398
  • 7
  • 62
  • 102
0

You could also use MEF, but be aware that MEF is not only for this purpose. Mostly MEF is a little oversized for normal DI scenarios, but very usefull if you intent to develop a extendible app.