Tuesday, 4 March 2014

Inversion of Control

 

 

Dependency Inversion

 

image

 

 

image

 

 

 

Dependency Inversion

 

Introduction

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

Bob’s Copy Program Example

 

Copy program without DIP

If we add more Writing functionality then this program will become more difficult and complicated because it lots more depending on lower modules.

 

image

 

 

Copy program with DIP

 

image

 

 

 

 

Layering

 

image

 

 

 

image

 

 

 

Button/Lamp Example

 

In this button Lamp example, button is dependent on Lamp.  If you want to control the Lamp in some other way or Use that button in some other purpose then it is very difficult.  As this implementation is tightly coupled.

 

image

 

 

This below implementation is Loosely coupled, we could add more devices in that button if we implement below design.

image

 

 

image

 

 

 

 

Inversion of Control

image

 

 

image

 

 

image

 

 

image

 

 

 

Interface Inversion

Interfaces without Inversion of Control

 

If we use more Interfaces then it will create problem when we use that interfaces in Client or user level.  For example, if you want to make match between IKangaroo and MikeTyson, you have to know about Method inside of those interfaces.  Here low level Kangaroo class define its own interface.

image

 

 

Here the Client boxing Match is creating IBoxer interface, all the low lever classes should implement this.

 

image

 

 

 

image

 

 

 

Flow Inversion

image

 

 

image

 

 

 

Creation Inversion

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

 

Dependency Injection

 

image

 

 

 

image

 

 

 

Below picture represent the Class with have all of its dependencies together.  Basically it does not implement dependency inversion.

image

 

 

 

Below picture represent the Class will get all of its dependencies from someone else like caterers.

 

image

 

 

 

image

 

 

 

Constructor Injection

 

image

 

 

image

 

 

 

Setting Injection

image

 

 

image

 

 

 

Interface Injection

 

image

 

 

image

 

 

 

image

 

 

image

 

 

 

 

Building an IoC Container

 

image

 

 

image

 

 

 

Visualizing Container

 

image

 

 

image

 

 

 

Demo of Manual Dependency Injection

 

image

 

 

image

 

 

image

 

 

image

 

 

 

Resolving Dependencies

image

 

 

 

Building the Real IOC Container

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

Using Unity

image

 

 

 

What is Unity?

image

 

 

 

Setting up Unity

image

 

 

image

 

 

 

Registering

image

 

 

 

Using the Container

 

image

 

 

 

image

 

 

Overriding Parameter

image

 

 

image

 

 

 

Controlling Life Cycle of Container Objects

 

Singleton Style

image

 

 

 

image

 

 

 

Using Castle Windsor

 

image

 

 

 

image

 

 

 

Setting up the Castle Windsor

 

image

 

 

 

image

 

 

image

 

 

 

Registering

image

 

 

 

Using the Castle Windsor

image

 

 

 

Controlling the Life Cycle of object

 

Singleton

image

 

 

image

 

 

Non Singleton

 

image

 

 

image

 

 

image

 

 

 

Using Structure Map

image

 

 

image

 

 

 

Setting up the Structure Map

 

image

 

 

image

 

 

 

image

 

 

image

 

 

 

Registering

image

 

 

 

Using the Container

image

 

 

 

Controlling Life Cycle

 

Not Singleton

image

 

 

image

 

 

 

Singleton

 

image

 

 

image

 

 

image

 

 

image

 

 

 

Using Ninject

image

 

 

 

What is Ninject

image

 

 

 

Setting up Ninject

 

image

 

 

image

 

 

image

 

 

 

Registering

image

 

 

 

Using the Container

 

image

 

 

image

 

 

image

 

 

 

Controlling Life Cycle

 

Non Singleton

image

 

 

image

 

 

Singleton

image

 

 

image

 

 

image

 

 

 

Blogger Labels: Inversion,Control,Dependency,Introduction,Copy,Program,Example,modules,Button,Lamp,purpose,implementation,Interface,Interfaces,Client,user,IKangaroo,MikeTyson,Method,Here,Kangaroo,Match,IBoxer,Creation,Injection,Class,dependencies,Constructor,Container,Demo,Manual,Real,Parameter,Life,Cycle,Objects,Singleton,Style,Castle,Windsor,Structure,Ninject

No comments:

Post a Comment