Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose a DI container? [duplicate]

Possible Duplicate:
How do the major C# DI/IoC frameworks compare?

There being so many DI containers, I feel kind of lost. I'm new to the DI pattern.

I'm reading the book Dependency Injection in .NET and I've found DI to be incredible useful in improving a code base, making it loose coupled and more testable.

I now want to introduce a DI container for my dummy project, but there are just so many to choose from.

How am I supposed to choose between Castle Windsor, Unity, StructureMap, Spring.NET, Autofac, Ninject, Funq, LinFu, etc, etc?

I guess a coherent take would be to "just pick one" and start using it (since I figure they're pretty easily interchangeable, specially in the early stages), but I would like to make a more informed decision.

like image 282
bevacqua Avatar asked Feb 25 '12 01:02

bevacqua


2 Answers

This is like buying a car. You might like a Toyota, but it's just 2.5L engine. You might like Ferrari, but it's too red. You might like Mazda, but your boss doesn't allow you to drive it. You might like Hummer, but then your colleagues would laugh at you. Mix the manufacturers to your taste, there's always going to be something missing for somebody or at some different moment.

My take is - first and foremost, DI is usually better then not having DI. Pick anything and you'll be better off. I'd pick something that:

  • Has good support in community (so you can get answers)
  • Has a good backing company behind it (so you don't get to rewrite your code when it goes bust)
  • Feels good to you (so you don't swear in front of the kids, not cool)
  • Is not an overkill for the project
  • Is not just DI, but offers an ecosystem of things that will reduce the time you spend on tasks that you know you can do, just not right now - and then you can focus on things that matter
  • Is used by a lot of people (so you know that many parts are also tested in real life and bugs filled)
  • Isn't 5 years old (such as that documentation says it is supported on Windows 98 or something)

My 2 cents - http://www.springframework.net/. I mean, their documentation contents page is like 20 pages long...

Or you just might want to look at some more answers to a similar question:

  • Which .NET Dependency Injection frameworks are worth looking into?
like image 142
icyrock.com Avatar answered Oct 07 '22 09:10

icyrock.com


You can start with the builtin DependencyResolver in MVC3. Later you can easily upgrade to Enterprise Library Unity DI.

Brad Wilson had mentioned a series of posts on How to use DI in MVC3.

like image 40
Manas Avatar answered Oct 07 '22 09:10

Manas