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?
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/
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