5

I am wondering what good simple IoC frameworks are there for asp.net mvc? that have good documentation and are just easy to get up and going.

Thanks

chobo2
  • 83,322
  • 195
  • 530
  • 832
  • 1
    Any decent IoC container ought to work well with ASP.NET MVC. Choose the one that best fits your sensibilities. – Robert Harvey May 06 '10 at 04:34
  • 2
    possible duplicate of http://stackoverflow.com/questions/21288/which-c-net-dependency-injection-frameworks-are-worth-looking-into, http://stackoverflow.com/questions/148908/which-dependency-injection-tool-should-i-use, http://stackoverflow.com/questions/2520089/autofac-or-ninject-which-should-i-go-for, http://stackoverflow.com/questions/411660/enterprise-library-unity-vs-other-ioc-containers, http://stackoverflow.com/questions/770039/examples-of-ioc-containers, etc. – Aaronaught May 06 '10 at 04:40
  • 1
    Looks like Aaronaught is right, though the other question is about a year old. Maybe make this a CW so information can be kept more or less current as frameworks evolve? – Roman May 06 '10 at 04:43
  • I added a few more dupe links... the other question may be old but I don't think the landscape has really changed much. The major players are the same - Autofac, Ninject, Windsor, Unity, StructureMap, etc. – Aaronaught May 06 '10 at 04:45
  • another one: http://stackoverflow.com/questions/532233/asp-net-mvc-fluent-nnibernate-what-ioc-tool – Mauricio Scheffer May 06 '10 at 13:37

5 Answers5

7

I've used Autofac and have been very happy with it.

Configuration is mostly done in code so you get compile time checking for your mappings as opposed to programming in XML and hoping for the best. It also supports XML overrides though so if you absolutely need to leave something to be configured at run/deploy time it's possible.

The Contrib (not sure what to call it?) portion provides integrations for NHibernate, Moq, etc. The creator of the project worked at Microsoft for a year on the MEF team so there's some MEF integration as well.

The documentation section of the site is pretty good (though if you don't find what you need there, it probably doesn't exist...yet). On the up side the author is on SO so if you have questions and tag the appropriately you could probably get quality answers.


You might also be interested in these two blog posts on organizing the configuration/wiring of your application to be cleaner.

  1. Using MEF and Castle Windsor to improve decoupling in your architecture
  2. NHibernate and WPF: The GuyWire - Although it's written in the context of WPF, the same concept would apply to a webapp.
Community
  • 1
  • 1
Roman
  • 19,581
  • 6
  • 68
  • 84
2

I use Windsor Castle, other people say that Structure Map is really good, but basically they all do the job

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Omu
  • 69,856
  • 92
  • 277
  • 407
1

S#arp Architecture is admittedly a lot more than just IoC. It uses Castle/Windsor for IoC.

I would recommend it as a larger set of best practices for the framework of your MVC application.

Jason Watts
  • 3,800
  • 29
  • 33
  • Castle/Windsor official site is weird. Cannot find there any samples of using the container. – zerkms May 06 '10 at 04:40
1

I have used Unity and it is good.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Karthik
  • 99
  • 1
  • 5
1

Danial Cazzulino has a bunch (scrunch?) of screencasts on creating the Funq DI Container. Funq is lightweight and fast but lacks some of the bells and whistles of the larger, more established frameworks.

I use the Funq-derived Munq which is also lightweight and fast and is a simple way to add a DI Container to MVC3 projects via Nuget. Up to now I haven't found any need to move to a different framework - Munq has been very adequate.

PM> install-package Munq.MVC3

This will add App_Start\MunqMvc3Startup.cs to the project, and this is where dependencies should be registered.

David Clarke
  • 12,888
  • 9
  • 86
  • 116