I've been looking for good dependency injection for ASP.NET MVC. recently I am Java EE programmer, I always used Spring for DI Framework. But after searching some tutorial from internet. Spring.NET requires explicit XML configuration for each controller that need to be injected.
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net">
<object id="HomeController" type="SpringTestApplication.Controllers.HomeController, SpringTestApplication" singleton="false">
<property name="TestProperty" value="This has been injected via Spring.Net"/>
</object>
</objects>
</spring>
And I think its very complected because there is no autowiring feature like Spring in Java World. Can you suggest me the recommended DI Framework for ASP.NET MVC ?
Thanks in advance.
I wouldn't say there is a de facto recommended DI framework for the ASP.NET MVC framework. However, there's quite a few popular DI framework in the .NET world: Castle Windsor, Autofac, StructureMap, Ninject, Unity, Sprint.NET etc.
I would definitely recommend Ninject. The source can be found on github. There is a Ninject extension for the various versions of the ASP.NET MVC framework. The project also contains a sample application.
If you would like to have a look at an application using Ninject in the wild I would recommend the blog engine Subtext.
May I also suggest that you have a look at Mark Seemann's book: Dependency Injection in .NET. It covers some of the major frameworks for .NET. Unfortunately, it does not cover Ninject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With