Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any build in Dependency injection container in .NET framework

As vNext has arrived we have a build in DI container that we can use as we need. But I also heard that earlier .NET frameworks also partially supports DI (not telling about Unity or any other container). For example, creation of a controller or a view in run time (I do not have wide knowledge about it). So I wanted to know is there any DI container already exist in earlier .NET frameworks, if there is any can we use them?

like image 995
Rahul Chakrabarty Avatar asked Sep 02 '25 08:09

Rahul Chakrabarty


1 Answers

There is no built in DI container in previous versions of ASP.NET. You can pretty easily setup and use the 3rd party ones (Ninject, Autofac, Castle Windsor, Unity, etc). They are all available on Nuget and can easily be added to an MVC project. There's a pretty good tutorial here for Unity: http://www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-dependency-injection

As for vNext, the ASP.NET team has different populators for common DI containers. You can review my overview of the built in one here: http://davidzych.com/2014/06/02/dependency-injection-in-asp-net-vnext/, and also my overview of setting up Castle Windsor in vNext here: http://davidzych.com/2014/07/28/asp-net-vnext-dependency-injection-with-castle-windsor/

like image 166
Dave Zych Avatar answered Sep 04 '25 21:09

Dave Zych