The IoC containers are used for dependency injection. There are many IoC containers, we use Ninject, as it is easy to use and understand. You can install the required package via NuGet. The package is called Ninject.MVC5.
After installing the package, we can already use Ninject in the project. For example, let's change the constructor of the controller as follows:
using Ninject;
//.....................
public class HomeController : Controller
{
IRepository repo;
public HomeController()
{
IKernel ninjectKernel = new StandardKernel();
ninjectKernel.Bind<IRepository>().To<BookRepository>();
repo = ninjectKernel.Get();
}
public ActionResult Index()
{
return View(repo.List());
}
}
Source: https://premius.net/blog/csharp-dotnet/136-using-ninject-in-c-asp-net-mvc5-projects.html