Dependency Inversion
Dependency Inversion
Introduction
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.
Copy program with DIP
Layering
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.
This below implementation is Loosely coupled, we could add more devices in that button if we implement below design.
Inversion of Control
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.
Here the Client boxing Match is creating IBoxer interface, all the low lever classes should implement this.
Flow Inversion
Creation Inversion
Dependency Injection
Below picture represent the Class with have all of its dependencies together. Basically it does not implement dependency inversion.
Below picture represent the Class will get all of its dependencies from someone else like caterers.
Constructor Injection
Setting Injection
Interface Injection
Building an IoC Container
Visualizing Container
Demo of Manual Dependency Injection
Resolving Dependencies
Building the Real IOC Container
Using Unity
What is Unity?
Setting up Unity
Registering
Using the Container
Overriding Parameter
Controlling Life Cycle of Container Objects
Singleton Style
Using Castle Windsor
Setting up the Castle Windsor
Registering
Using the Castle Windsor
Controlling the Life Cycle of object
Singleton
Non Singleton
Using Structure Map
Setting up the Structure Map
Registering
Using the Container
Controlling Life Cycle
Not Singleton
Singleton
Using Ninject
What is Ninject
Setting up Ninject
Registering
Using the Container
Controlling Life Cycle
Non Singleton
Singleton
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