Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the recommended Dependency Injection framework for ASP.NET MVC

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.

like image 699
Adi Sembiring Avatar asked May 26 '11 15:05

Adi Sembiring


1 Answers

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.

like image 174
mrydengren Avatar answered Oct 23 '22 10:10

mrydengren