SlideShare a Scribd company logo
1 of 27
Download to read offline
Inversion of Control (IoC)
Dependency Injection (DI)
Milan Negovan
MILAN
NEGOVAN
ROASTS ASP.NET WITH WEB STANDARDS
ASP.NET CONSULTING SERVICES
http://aspnetresources.com
milan@aspnetresources.com
Example
a Contact Us web page
1.Collect personal info from server controls
2.Process user's info
1. Build an email (text or HTML, in what
format?)
2.Create an SMTP client
3.Send email
3.Handle exceptions, if any
4.Anything else?
Take 1
1.Collect personal info from server controls
2.Process user's info
1. Build an email (text or HTML, in what
format?)
2.Create an SMTP client
3.Send email
3.Handle exceptions, if any
4.Anything else?
Take 1
Cohesion
a measure of how strongly-
related and focused the various
responsibilities of a software
module are.
Coupling
the degree of direct knowledge
that one class has of another.
Strong coupling: a dependent class
contains a pointer directly to a
concrete class which provides the
required behavior.
Loose coupling: the dependent class
contains a pointer only to an interface,
which can then be implemented by
one or many concrete classes.
High cohesion: good
Loose coupling: good
1.Collect personal info from server controls
2.Let something else process user's info
Take 2
Dependency Injection (DI)
the process of supplying an external
dependency
3 elements of DI
Two primary approaches to DI:
constructor injection and
setter injection
So what is IoC about?
IoC is about
... looser coupling of components
IoC is about
... pushing dependencies outside of
your code
IoC is about
... less code duplication
IoC is about
... testing through mocking dependencies
IoC is about
... isolating changes
IoC is about
... swapping dependencies for different
environments
IoC is an architectural
principle
DI is its implementation.
Costs and benefits of unit testing
http://blog.stevensanderson.com/2009/11/04/selective-unit-testing-costs-and-benefits/
Diagram by Steve Sanderson
Boil WebForms down to
coordinators!
IoC containers for .NET
Spring.NET
StructureMap
Caslte Windsor
Unity
Managed Extensibility Framework (MEF)
Autofac
Demo
real-world DI
Group therapy
benefits and drawbacks of IoC

More Related Content

Similar to IoC_and_DI

Dependency Injection & IoC
Dependency Injection & IoCDependency Injection & IoC
Dependency Injection & IoCDennis Loktionov
 
Dependency injection and inversion
Dependency injection and inversionDependency injection and inversion
Dependency injection and inversionchhabraravish23
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCJulia Vi
 
Pentesting With Web Services in 2012
Pentesting With Web Services in 2012Pentesting With Web Services in 2012
Pentesting With Web Services in 2012Ishan Girdhar
 
SOME INTEROPERABILITY ISSUES IN THE DESIGNING OF WEB SERVICES : CASE STUDY ON...
SOME INTEROPERABILITY ISSUES IN THE DESIGNING OF WEB SERVICES : CASE STUDY ON...SOME INTEROPERABILITY ISSUES IN THE DESIGNING OF WEB SERVICES : CASE STUDY ON...
SOME INTEROPERABILITY ISSUES IN THE DESIGNING OF WEB SERVICES : CASE STUDY ON...ijwscjournal
 
Microsoft remote connectivity analyzer (exrca) autodiscover troubleshooting ...
Microsoft remote connectivity analyzer (exrca)  autodiscover troubleshooting ...Microsoft remote connectivity analyzer (exrca)  autodiscover troubleshooting ...
Microsoft remote connectivity analyzer (exrca) autodiscover troubleshooting ...Eyal Doron
 
Microsoft remote connectivity analyzer (ex rca) autodiscover troubleshooting...
Microsoft remote connectivity analyzer (ex rca)  autodiscover troubleshooting...Microsoft remote connectivity analyzer (ex rca)  autodiscover troubleshooting...
Microsoft remote connectivity analyzer (ex rca) autodiscover troubleshooting...Eyal Doron
 
.NET,ASP .NET, Angular Js,LinQ
.NET,ASP .NET, Angular Js,LinQ.NET,ASP .NET, Angular Js,LinQ
.NET,ASP .NET, Angular Js,LinQAvijit Shaw
 
Dissertation - Ashley Kingscote
Dissertation - Ashley KingscoteDissertation - Ashley Kingscote
Dissertation - Ashley KingscoteAshley Kingscote
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstEnea Gabriel
 
A Deep Dive in the World of IT Networking (Part 2)
A Deep Dive in the World of IT Networking (Part 2)A Deep Dive in the World of IT Networking (Part 2)
A Deep Dive in the World of IT Networking (Part 2)Tuan Yang
 
Ccna 1 chapter 3 v4.0 answers 100 updated 2011
Ccna 1 chapter 3 v4.0 answers 100 updated 2011Ccna 1 chapter 3 v4.0 answers 100 updated 2011
Ccna 1 chapter 3 v4.0 answers 100 updated 2011Dân Chơi
 
Patterns&Antipatternsof SOA
Patterns&Antipatternsof SOAPatterns&Antipatternsof SOA
Patterns&Antipatternsof SOAMohamed Samy
 
Complete the following in a Word document titled 1 In.docx
Complete the following in a Word document titled 1 In.docxComplete the following in a Word document titled 1 In.docx
Complete the following in a Word document titled 1 In.docxwrite22
 
Web Service Oriented Architecture
Web Service Oriented ArchitectureWeb Service Oriented Architecture
Web Service Oriented ArchitectureJorgen Thelin
 
Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Steve Lange
 

Similar to IoC_and_DI (20)

Dependency Injection & IoC
Dependency Injection & IoCDependency Injection & IoC
Dependency Injection & IoC
 
website phishing by NR
website phishing by NRwebsite phishing by NR
website phishing by NR
 
Dependency injection and inversion
Dependency injection and inversionDependency injection and inversion
Dependency injection and inversion
 
A26001006
A26001006A26001006
A26001006
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Pentesting With Web Services in 2012
Pentesting With Web Services in 2012Pentesting With Web Services in 2012
Pentesting With Web Services in 2012
 
SOME INTEROPERABILITY ISSUES IN THE DESIGNING OF WEB SERVICES : CASE STUDY ON...
SOME INTEROPERABILITY ISSUES IN THE DESIGNING OF WEB SERVICES : CASE STUDY ON...SOME INTEROPERABILITY ISSUES IN THE DESIGNING OF WEB SERVICES : CASE STUDY ON...
SOME INTEROPERABILITY ISSUES IN THE DESIGNING OF WEB SERVICES : CASE STUDY ON...
 
Microsoft remote connectivity analyzer (exrca) autodiscover troubleshooting ...
Microsoft remote connectivity analyzer (exrca)  autodiscover troubleshooting ...Microsoft remote connectivity analyzer (exrca)  autodiscover troubleshooting ...
Microsoft remote connectivity analyzer (exrca) autodiscover troubleshooting ...
 
Microsoft remote connectivity analyzer (ex rca) autodiscover troubleshooting...
Microsoft remote connectivity analyzer (ex rca)  autodiscover troubleshooting...Microsoft remote connectivity analyzer (ex rca)  autodiscover troubleshooting...
Microsoft remote connectivity analyzer (ex rca) autodiscover troubleshooting...
 
.NET,ASP .NET, Angular Js,LinQ
.NET,ASP .NET, Angular Js,LinQ.NET,ASP .NET, Angular Js,LinQ
.NET,ASP .NET, Angular Js,LinQ
 
Dissertation - Ashley Kingscote
Dissertation - Ashley KingscoteDissertation - Ashley Kingscote
Dissertation - Ashley Kingscote
 
Walther Mvc
Walther MvcWalther Mvc
Walther Mvc
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Onine exam 1
Onine exam 1Onine exam 1
Onine exam 1
 
A Deep Dive in the World of IT Networking (Part 2)
A Deep Dive in the World of IT Networking (Part 2)A Deep Dive in the World of IT Networking (Part 2)
A Deep Dive in the World of IT Networking (Part 2)
 
Ccna 1 chapter 3 v4.0 answers 100 updated 2011
Ccna 1 chapter 3 v4.0 answers 100 updated 2011Ccna 1 chapter 3 v4.0 answers 100 updated 2011
Ccna 1 chapter 3 v4.0 answers 100 updated 2011
 
Patterns&Antipatternsof SOA
Patterns&Antipatternsof SOAPatterns&Antipatternsof SOA
Patterns&Antipatternsof SOA
 
Complete the following in a Word document titled 1 In.docx
Complete the following in a Word document titled 1 In.docxComplete the following in a Word document titled 1 In.docx
Complete the following in a Word document titled 1 In.docx
 
Web Service Oriented Architecture
Web Service Oriented ArchitectureWeb Service Oriented Architecture
Web Service Oriented Architecture
 
Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)
 

IoC_and_DI