Book Image

Mastering Ninject for Dependency Injection

By : Daniel Baharestani
Book Image

Mastering Ninject for Dependency Injection

By: Daniel Baharestani

Overview of this book

Dependency injection is an approach to creating loosely coupled applications. Maintainability, testability, and extensibility are just a few advantages of loose coupling. Ninject is a software library which automates almost everything that we need in order to implement a dependency injection pattern. Mastering Ninject for Dependency Injection will teach you everything you need to know in order to implement dependency injection using Ninject in a real-life project. Not only does it teach you about Ninject core framework features that are essential for implementing dependency injection, but it also explores the power of Ninject's most useful extensions and demonstrates how to apply them. Mastering Ninject for Dependency Injection starts by introducing you to dependency injection and what it's meant for with the help of sufficient examples. Eventually, you'll learn how to integrate Ninject into your practical project and how to use its basic features. Also, you will go through scenarios wherein advanced features of Ninject, such as Multi-binding, Contextual binding, providers, factories and so on, come into play. As you progress, Mastering Ninject for Dependency Injection will show you how to create a multilayer application that demonstrates the use of Ninject on different application types such as MVC, WPF, WCF, and so on. Finally, you will learn the benefits of using the powerful extensions of Ninject.
Table of Contents (12 chapters)

ASP.NET MVC applications


Using Ninject in Windows client applications (WPF and Windows Forms) was not much different from using it in a Console application. We didn't need any certain configuration to set up Ninject in such applications, because in Windows client applications the developer has the control of instantiating UI components (Forms or Windows), and can easily delegate this control to Ninject. In Web applications, however, it is not the same, because the framework is responsible of instantiating the UI. So, we need to somehow tell the framework to delegate that responsibility to Ninject. Fortunately, asking the ASP.NET .MVC framework to do so is easily possible, but it is not the same for Web Forms applications.

Thanks to Ninject's MVC extension, we don't even need to bother setting up MVC framework to support DI. Instead, Ninject's MVC extension will do it for us. In this section, we will implement the Northwind customers scenario using Ninject in an ASP.NET MVC 3 application....