Mastering Ninject for Dependency Injection

Book description

For .NET developers and architects, this is the ultimate guide to the principles of Dependency Injection and how to use the automating features of Ninject in the most effective way. Packed with examples, diagrams, and illustrations.

  • Create loosely coupled applications by implementing dependency injection using Ninject
  • Learn how to design an enterprise application so as to maximize its maintainability, extensibility and testability
  • Automate the process of dealing with the dependencies of your application and object lifetimes
  • Address the cross-cutting concerns of your applications in the easiest way
  • Full of real-life, step-by-step examples and clear code samples

In Detail

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

  1. Mastering Ninject for Dependency Injection
    1. Table of Contents
    2. Mastering Ninject for Dependency Injection
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Understanding Dependency Injection
      1. What is Dependency Injection?
        1. DI or Inversion of Control (IoC)
      2. How can DI help?
      3. My First DI Application
      4. DI Containers
      5. Why use Ninject?
      6. Summary
    9. 2. Getting Started with Ninject
      1. Hello Ninject!
      2. It's all about Binding
      3. Object Lifetime
        1. Transient scope
        2. Singleton scope
        3. Thread scope
        4. Request scope
        5. Custom scope
      4. Ninject modules
      5. XML configuration
        1. How to use XML configuration
      6. Convention over configuration
        1. Selecting the assemblies
        2. Selecting the components
          1. Filtering the selected components
          2. Explicit inclusion and exclusion
        3. Selecting service types
        4. Configuring the Bindings
      7. Summary
    10. 3. Meeting Real-world Requirements
      1. DI patterns and antipatterns
        1. Constructor Injection
        2. Initializer methods and properties
        3. Service Locator
      2. Multi binding and contextual binding
        1. Implementing the plugin model
        2. Contextual binding
          1. Named binding
          2. Resolving metadata
          3. Attribute-based binding
          4. Target-based conditions
          5. Generic helper
      3. Custom providers
        1. Activation context
        2. Factory Methods
      4. Dynamic factories
        1. The Shape Factory example
        2. Using convention
          1. Selecting service types
          2. Defining Binding Generator
        3. Telecom Switch example
        4. Custom Instance Providers
        5. Func
        6. Lazy
      5. Summary
    11. 4. Ninject in Action
      1. Windows Forms applications
      2. WPF and Silverlight applications
      3. ASP.NET MVC applications
        1. Validator injection
        2. Filter injection
          1. Conditional filtering (When)
          2. Contextual arguments (With)
      4. WCF applications
      5. ASP.NET Web Forms applications
      6. Summary
    12. 5. Doing More with Extensions
      1. Interception
        1. Setup Interception
        2. Member Interception
        3. Type Interception
        4. Multiple Interceptors
        5. Intercept Attribute
      2. Mocking Kernel
      3. Extending Ninject
      4. Summary
    13. Index

Product information

  • Title: Mastering Ninject for Dependency Injection
  • Author(s): Daniel Baharestani
  • Release date: September 2013
  • Publisher(s): Packt Publishing
  • ISBN: 9781782166207