Mastering Ninject for Dependency Injection
eBook - ePub

Mastering Ninject for Dependency Injection

  1. 142 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Ninject for Dependency Injection

About this book

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.

Approach

Mastering Ninject for Dependency Injection teaches you the most powerful concepts of Ninject in a simple and easy-to-understand format using lots of practical examples, diagrams, and illustrations.

Who this book is for

Mastering Ninject for Dependency Injection is aimed at software developers and architects who wish to create maintainable, extensible, testable, and loosely coupled applications. Since Ninject targets the .NET platform, this book is not suitable for software developers of other platforms. Being familiar with design patterns such as singleton or factory would be beneficial, but no knowledge of dependency injection or IoC is assumed.

Trusted by 375,005 students

Access to over 1 million titles for a fair monthly price.

Study more efficiently using our study tools.

Information

Mastering Ninject for Dependency Injection


Table of Contents

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

Mastering Ninject for Dependency Injection

Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: September 2013
Production Reference: 1190913
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK..
ISBN 978-1-78216-620-7
www.packtpub.com
Cover Image by Daniel Baharestani () and Sheetal Aute ()

Credits

Author
Daniel Baharestani
Reviewers
Remo Gloor
Daniel Allen
Matt Duffield
Ted Winslow
Acquisition Editor
Pramila Balan
Commissioning Editor
Nikhil Chinnari
Technical Editors
Iram Malik
Krishnaveni Haridas
Veena Pagare
Project Coordinator
Romal Karani
Proofreader
Clyde Jenkins
Indexer
Monica Ajmera
Graphics
Ronak Dhruv
Production Coordinator
Conidon Miranda
Cover Work
Conidon Miranda

About the Author

Daniel Baharestani is an experienced IT professional living in Australia. He has a BSc in software engineering and has over 10 years of professional experience in design and development of enterprise applications, mostly focused on Microsoft technologies. Daniel is currently working at 3P Learning, which is a global leader in online learning for school-aged students with its flagship platform, Mathletics—used by more than 3.5 million students in over 10,000 schools worldwide.

About the Reviewers

Remo Gloor has worked as a Software Architect at bbv Software Services AG in Switzerland for many years. During this time, he was using Ninject in several projects. At the beginning, he was a user of Ninject. Later, he contributed with several extensions. In 2010, he became manager and the main contributor to Ninject, which was developed originally by Nate Kohari and Ian Davis.
Besides his interest in dependency injection and IoC containers, he has also a strong interest in service-oriented and message-driven architectures, as well as event sourcing. Because of this, he contributed to the ActiveMq support to NServiceBus.
He blogs on http://www.planetgeek.ch/author/remo-gloor/ mainly about Ninject. He also answers many Ninject-related questions on stackoverflow: http://stackoverflow.com/users/448580/remo-gloor.
Daniel Allen is a Chicago-based developer who specializes in ASP.NET MVC 4 development and enterprise architecture design. He develops primarily in C#, JavaScript, and Objective-C. Because of his heavy focus on enterprise architecture design, Dan has experience in an array of patterns and tools that he has effectively and logically combined together to meet a project's unique needs. Dan holds a B.S. in Management Information Systems and an MBA with a concentration in Information Systems.
Dan spends much of his free time working on development-related side contracts and searching for the next great startup idea. He aspires to start a consulting firm that will provide capital for the various startup ideas one day. For recreation, he enjoys ...

Table of contents

  1. Mastering Ninject for Dependency Injection

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Mastering Ninject for Dependency Injection by Daniel Baharestani in PDF and/or ePUB format, as well as other popular books in Computer Science & Microsoft Programming. We have over one million books available in our catalogue for you to explore.