SlideShare a Scribd company logo
1 of 44
Dependencies
Demystified
Jason Bock
Practice Lead
»http://www.magenic.com
»http://www.jasonbock.net
»https://www.twitter.com/jasonbock
»https://www.github.com/jasonbock
»jasonb@magenic.com
Personal Info
Downloads
https://github.com/JasonBock/
DependenciesDemystified
http://www.slideshare.net/jasonbock/
dependencies-demystified
»Dependencies
»Containers
Overview
Remember…
https://github.com/JasonBock/
DependenciesDemystified
http://www.slideshare.net/jasonbock/
dependencies-demystified
Dependencies
Dependencies
Dependencies
Dependencies
Dependencies
Dependencies
Dependencies
Dependencies
They're resources that you use
in code that perform
functions/services that you
need.
Dependencies
Code DB
Dependencies
Code
DB
DB
Interface
Dependencies
"Program to an
interface, not an
implementation"
Dependencies
http://listcrux.com/wp-content/uploads/2013/12/Blame-Game.jpg
Dependencies
http://westsmog.com/wp-content/uploads/2011/11/PassFail-Small.jpg
Dependencies
Code
SQL
Server
DB
Interface
Oracle MySQL
Dependencies
Files
Services
Databases
Time
Randomness
Dependencies
CoreTypes
Algorithms
Demo: Refactoring Code to Use
Dependencies
Dependencies Demystified
Containers
Code
Dependency
Code
Code
Code
Code
Code
Containers
Virtualize “new”!
…or not?
Containers
Code
IoC.Container
Code
Code
Code
Code
Code
Containers
Code
Composition
Root
Code
Code
Code
Code
Code
Containers
Register
Resolve
Release
Demo: DIY IOC Implementation
Dependencies Demystified
Containers
http://netstorage.discovery.com/feeds/brightcove/asset-
stills/dsc/136734381737214045601501197_SQUARE_WHEELS.jpg
Containers
• RelationshipTypes
• Transient
• Singleton
• Lazy
• And others
• Object Lifetimes
Containers
Singleton
Parentpublic sealed class DependentChild
{
private readonly IParent parent;
public DependentChild(IParent parent)
{
if(parent == null)
{
throw new ArgumentNullException(nameof(parent));
}
this.parent = parent;
}
Random
Parent
Dependency Registration
Containers
Registered
Parent
public sealed class DependentChild
{
private readonly Lazy<IParent> parent;
public DependentChild(Lazy<IParent> parent)
{
if(parent == null)
{
throw new ArgumentNullException(nameof(parent));
}
this.parent = parent;
}
Dependency Usage
Containers
IDisposableParent :
IParent, IDisposable
public sealed class DependentChild
{
private readonly IParent parent;
public DependentChild(IParent parent)
{
if(parent == null)
{
throw new ArgumentNullException(nameof(parent));
}
this.parent = parent;
}
Disposable Dependencies
Containers
• StructureMap
• Unity
• Autofac
• Ninject
• LinFu
• Funq
• And, like, a thousand others 
Containers
http://i5.asn.im/couple-arguing-_ucgr.jpg
Containers
http://www.emacswiki.org/pics/static/TabsSpacesBoth.png
Containers
http://autofac.org/
Containers
http://www.palmmedia.de/Blog/2011/8/30/ioc-container-benchmark-performance-comparison
Demo: Using Autofac
Dependencies Demystified
Containers
Console
XAML
WebApi
WinService
Containers
Console
XAML
WebApi
WinService
Container
Containers
public interface IDependencyResolver : IDependencyScope, IDisposable
{
IDependencyScope BeginScope();
}
public interface IDependencyScope : IDisposable
{
object GetService(Type serviceType);
IEnumerable<object> GetServices(Type serviceType);
}
Demo: Autofac and WebApi Integration
Dependencies Demystified
Conclusion
“The reason that I use IoC is not to
encourage testing, it is not to break
dependencies, it is not to get separation
of concerns…I am using IoC because it
makes all of the above so easy.”
http://ayende.com/blog/2887/dependency-injection-doesnt-cut-it-anymore
Dependencies
Demystified
Jason Bock
Practice Lead
Remember…
 https://github.com/JasonBock/DependenciesDemystified
 http://www.slideshare.net/jasonbock/dependencies-demystified
 References in the notes on this slide

More Related Content

What's hot

High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)Steve Souders
 
State of the resource timing api
State of the resource timing apiState of the resource timing api
State of the resource timing apiAaron Peters
 
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...Lincoln III
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)Steve Souders
 
Beautiful Java EE - PrettyFaces
Beautiful Java EE - PrettyFacesBeautiful Java EE - PrettyFaces
Beautiful Java EE - PrettyFacesLincoln III
 
High Performance Web Components
High Performance Web ComponentsHigh Performance Web Components
High Performance Web ComponentsSteve Souders
 
Seo - Search Engine Optimization seminar
Seo - Search Engine Optimization seminarSeo - Search Engine Optimization seminar
Seo - Search Engine Optimization seminarcooljeba
 
Prebrowsing - Velocity NY 2013
Prebrowsing - Velocity NY 2013Prebrowsing - Velocity NY 2013
Prebrowsing - Velocity NY 2013Steve Souders
 
Accessibility - A feature you can build
Accessibility - A feature you can buildAccessibility - A feature you can build
Accessibility - A feature you can buildMonika Piotrowicz
 
Real World Web Standards
Real World Web StandardsReal World Web Standards
Real World Web Standardsgleddy
 
Extending & Scaling | Dallas PHP
Extending & Scaling | Dallas PHPExtending & Scaling | Dallas PHP
Extending & Scaling | Dallas PHPrandyhoyt
 
Html5的应用与推行
Html5的应用与推行Html5的应用与推行
Html5的应用与推行Sofish Lin
 
Website Audit [On Page and Off Page] by Carl Benedic Pantaleon
Website Audit [On Page and Off Page] by Carl Benedic PantaleonWebsite Audit [On Page and Off Page] by Carl Benedic Pantaleon
Website Audit [On Page and Off Page] by Carl Benedic PantaleonJacque Doring
 
Web Apps and more
Web Apps and moreWeb Apps and more
Web Apps and moreYan Shi
 
Building Mobile Applications with Ionic
Building Mobile Applications with IonicBuilding Mobile Applications with Ionic
Building Mobile Applications with IonicMorris Singer
 
Web Apps for the Masses
Web Apps for the MassesWeb Apps for the Masses
Web Apps for the MassesDavid Tufts
 
Microformats HTML to API
Microformats HTML to APIMicroformats HTML to API
Microformats HTML to APIelliando dias
 
How fast are we going now?
How fast are we going now?How fast are we going now?
How fast are we going now?Steve Souders
 

What's hot (20)

High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)
 
State of the resource timing api
State of the resource timing apiState of the resource timing api
State of the resource timing api
 
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
Beautiful Java EE - PrettyFaces
Beautiful Java EE - PrettyFacesBeautiful Java EE - PrettyFaces
Beautiful Java EE - PrettyFaces
 
High Performance Web Components
High Performance Web ComponentsHigh Performance Web Components
High Performance Web Components
 
Seo - Search Engine Optimization seminar
Seo - Search Engine Optimization seminarSeo - Search Engine Optimization seminar
Seo - Search Engine Optimization seminar
 
Prebrowsing - Velocity NY 2013
Prebrowsing - Velocity NY 2013Prebrowsing - Velocity NY 2013
Prebrowsing - Velocity NY 2013
 
Introduction to HTML5 & CSS3
Introduction to HTML5 & CSS3Introduction to HTML5 & CSS3
Introduction to HTML5 & CSS3
 
Accessibility - A feature you can build
Accessibility - A feature you can buildAccessibility - A feature you can build
Accessibility - A feature you can build
 
Real World Web Standards
Real World Web StandardsReal World Web Standards
Real World Web Standards
 
Extending & Scaling | Dallas PHP
Extending & Scaling | Dallas PHPExtending & Scaling | Dallas PHP
Extending & Scaling | Dallas PHP
 
Html5的应用与推行
Html5的应用与推行Html5的应用与推行
Html5的应用与推行
 
Website Audit [On Page and Off Page] by Carl Benedic Pantaleon
Website Audit [On Page and Off Page] by Carl Benedic PantaleonWebsite Audit [On Page and Off Page] by Carl Benedic Pantaleon
Website Audit [On Page and Off Page] by Carl Benedic Pantaleon
 
Design+Performance
Design+PerformanceDesign+Performance
Design+Performance
 
Web Apps and more
Web Apps and moreWeb Apps and more
Web Apps and more
 
Building Mobile Applications with Ionic
Building Mobile Applications with IonicBuilding Mobile Applications with Ionic
Building Mobile Applications with Ionic
 
Web Apps for the Masses
Web Apps for the MassesWeb Apps for the Masses
Web Apps for the Masses
 
Microformats HTML to API
Microformats HTML to APIMicroformats HTML to API
Microformats HTML to API
 
How fast are we going now?
How fast are we going now?How fast are we going now?
How fast are we going now?
 

Similar to Dependencies Demystified

Code Reactions - An Introduction to Reactive Extensions
Code Reactions - An Introduction to Reactive ExtensionsCode Reactions - An Introduction to Reactive Extensions
Code Reactions - An Introduction to Reactive Extensionsjasonbock
 
Web Development for UX Designers
Web Development for UX DesignersWeb Development for UX Designers
Web Development for UX DesignersAshlimarie
 
AtlasCamp 2011 - Five Strategies to Accelerate Plugin Development
AtlasCamp 2011 - Five Strategies to Accelerate Plugin DevelopmentAtlasCamp 2011 - Five Strategies to Accelerate Plugin Development
AtlasCamp 2011 - Five Strategies to Accelerate Plugin Developmentmrdon
 
Web Performance & You
Web Performance & YouWeb Performance & You
Web Performance & YouDave Olsen
 
The Server Side of Responsive Web Design
The Server Side of Responsive Web DesignThe Server Side of Responsive Web Design
The Server Side of Responsive Web DesignDave Olsen
 
Develop your first mobile App for iOS and Android
Develop your first mobile App for iOS and AndroidDevelop your first mobile App for iOS and Android
Develop your first mobile App for iOS and Androidralcocer
 
Develop your first mobile App for iOS and Android
Develop your first mobile App for iOS and AndroidDevelop your first mobile App for iOS and Android
Develop your first mobile App for iOS and AndroidRicardo Alcocer
 
Measuring Web Performance - HighEdWeb Edition
Measuring Web Performance - HighEdWeb EditionMeasuring Web Performance - HighEdWeb Edition
Measuring Web Performance - HighEdWeb EditionDave Olsen
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Nicholas Zakas
 
Rubbing the Sankara Stones the wrong way - From the Front 2014
Rubbing the Sankara Stones the wrong way - From the Front 2014Rubbing the Sankara Stones the wrong way - From the Front 2014
Rubbing the Sankara Stones the wrong way - From the Front 2014Christian Heilmann
 
Web app and more
Web app and moreWeb app and more
Web app and morefaming su
 
REST API Pentester's perspective
REST API Pentester's perspectiveREST API Pentester's perspective
REST API Pentester's perspectiveSecuRing
 
Debugging rendering problems at scale
Debugging rendering problems at scaleDebugging rendering problems at scale
Debugging rendering problems at scaleGiacomo Zecchini
 
Introduction to The Scalable JavaScript Application Framework
Introduction to The Scalable JavaScript Application FrameworkIntroduction to The Scalable JavaScript Application Framework
Introduction to The Scalable JavaScript Application FrameworkEric Bréchemier
 
DevOps + MongoDB Realm Serverless Functions = 🤩
DevOps + MongoDB Realm Serverless Functions = 🤩DevOps + MongoDB Realm Serverless Functions = 🤩
DevOps + MongoDB Realm Serverless Functions = 🤩Lauren Hayward Schaefer
 
Measuring Web Performance (HighEdWeb FL Edition)
Measuring Web Performance (HighEdWeb FL Edition)Measuring Web Performance (HighEdWeb FL Edition)
Measuring Web Performance (HighEdWeb FL Edition)Dave Olsen
 
Dependency Injection in Silverlight
Dependency Injection in SilverlightDependency Injection in Silverlight
Dependency Injection in SilverlightCaleb Jenkins
 
Engineering the New LinkedIn Profile
Engineering the New LinkedIn ProfileEngineering the New LinkedIn Profile
Engineering the New LinkedIn ProfileJosh Clemm
 
DF Global Gathering PuneWIT
DF Global Gathering PuneWITDF Global Gathering PuneWIT
DF Global Gathering PuneWITDaniel Peter
 

Similar to Dependencies Demystified (20)

Code Reactions - An Introduction to Reactive Extensions
Code Reactions - An Introduction to Reactive ExtensionsCode Reactions - An Introduction to Reactive Extensions
Code Reactions - An Introduction to Reactive Extensions
 
Web Development for UX Designers
Web Development for UX DesignersWeb Development for UX Designers
Web Development for UX Designers
 
AtlasCamp 2011 - Five Strategies to Accelerate Plugin Development
AtlasCamp 2011 - Five Strategies to Accelerate Plugin DevelopmentAtlasCamp 2011 - Five Strategies to Accelerate Plugin Development
AtlasCamp 2011 - Five Strategies to Accelerate Plugin Development
 
Web Performance & You
Web Performance & YouWeb Performance & You
Web Performance & You
 
The Server Side of Responsive Web Design
The Server Side of Responsive Web DesignThe Server Side of Responsive Web Design
The Server Side of Responsive Web Design
 
Develop your first mobile App for iOS and Android
Develop your first mobile App for iOS and AndroidDevelop your first mobile App for iOS and Android
Develop your first mobile App for iOS and Android
 
Develop your first mobile App for iOS and Android
Develop your first mobile App for iOS and AndroidDevelop your first mobile App for iOS and Android
Develop your first mobile App for iOS and Android
 
Measuring Web Performance - HighEdWeb Edition
Measuring Web Performance - HighEdWeb EditionMeasuring Web Performance - HighEdWeb Edition
Measuring Web Performance - HighEdWeb Edition
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)
 
Rubbing the Sankara Stones the wrong way - From the Front 2014
Rubbing the Sankara Stones the wrong way - From the Front 2014Rubbing the Sankara Stones the wrong way - From the Front 2014
Rubbing the Sankara Stones the wrong way - From the Front 2014
 
Web app and more
Web app and moreWeb app and more
Web app and more
 
REST API Pentester's perspective
REST API Pentester's perspectiveREST API Pentester's perspective
REST API Pentester's perspective
 
Debugging rendering problems at scale
Debugging rendering problems at scaleDebugging rendering problems at scale
Debugging rendering problems at scale
 
Introduction to The Scalable JavaScript Application Framework
Introduction to The Scalable JavaScript Application FrameworkIntroduction to The Scalable JavaScript Application Framework
Introduction to The Scalable JavaScript Application Framework
 
DevOps + MongoDB Realm Serverless Functions = 🤩
DevOps + MongoDB Realm Serverless Functions = 🤩DevOps + MongoDB Realm Serverless Functions = 🤩
DevOps + MongoDB Realm Serverless Functions = 🤩
 
Measuring Web Performance (HighEdWeb FL Edition)
Measuring Web Performance (HighEdWeb FL Edition)Measuring Web Performance (HighEdWeb FL Edition)
Measuring Web Performance (HighEdWeb FL Edition)
 
Dependency Injection in Silverlight
Dependency Injection in SilverlightDependency Injection in Silverlight
Dependency Injection in Silverlight
 
Engineering the New LinkedIn Profile
Engineering the New LinkedIn ProfileEngineering the New LinkedIn Profile
Engineering the New LinkedIn Profile
 
DF Global Gathering PuneWIT
DF Global Gathering PuneWITDF Global Gathering PuneWIT
DF Global Gathering PuneWIT
 
Building Web Hack Interfaces
Building Web Hack InterfacesBuilding Web Hack Interfaces
Building Web Hack Interfaces
 

Recently uploaded

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 

Recently uploaded (20)

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 

Dependencies Demystified

Editor's Notes

  1. Dependencies….what are they? Why should I care? Don’t they just make everything harder? I can easily connect to my service or database in code, what’s with all this misdirection, extra layers? Is this another form of job security? Even though it really is a simple concept, it took me a while to really get my head around dependencies. But if you start to recognize dependencies in code and handle them correctly, the benefits are tremendous.
  2. We know a lot about how to write good code, and these books (among others) have good information about how to do it. Let’s focus in on the dependency aspect with a real-world example
  3. I have two kids
  4. They’re dependent on me. Sometimes they make requests from me, like “give me money!”
  5. I may return 0, or RoomNotCleanedException. (or even -2)
  6. Or I may pay them for their hard work (a quarter is a quarter!)
  7. If I don't work, make money, pay the mortgage, get groceries, etc. I turn into a null reference, and that's not good.
  8. That’s all dependencies are. This is the simplest answer I could come up with off the top of my head
  9. A canonical example is DB access. You can write code that talks to a database directly, or…
  10. You can use an interface instead. The implementation is given to you, but you don’t know or care how it’s implemented. You just use the interface definition. Note that this is usually passed into an object on construction. There are other ways to do it, but the majority of the time it’s constructor injection.
  11. This is one of the best quotes in Design Patterns. The patterns themselves are good, but they’re all based on this premise. You don’t want to how the patterns are implemented, you just want to use them in a pluggable way.
  12. And why is this beneficial? One, you can blame others . In a way, this is a good thing. You don’t want that responsibility! Put the details of how to create the dependency somewhere else…in a central location…we’ll get back to that later.
  13. It can make testing easier. You don’t have to have N number of dependencies up and running just to see if the code under test works. Integration/end-to-end testing is definitely needed, but having a suite of fast unit tests is a beautiful thing to have.
  14. It also has the benefit that you can use different implementations, though I've personally not found that to be a huge win (YMMV)
  15. What are some examples of typical dependencies? Files: Code that uses files doesn’t need to actually create the file. Interfaces are sufficient for this (like streams, or libraries like System.IO.Abstractions - https://github.com/tathamoddie/System.IO.Abstractions) Services: Talking to a back-end REST or WCF service isn’t the goal: getting or updating information via these services iss Databases: see above  Time: Time can be hard to manage, especially in testing scenarios, where “DateTime.UtcNow” just doesn’t give enough fine grain control. Having a dependency provide time is a good thing (Reactive Extensions provides this via IScheduler) Randomness: Ever try to test code that uses random data? Or what if you want to switch the random generator out? This isn’t a complete list. You may choose to define other dependencies
  16. What are some examples of atypical dependencies? Core Types - things like int, string, etc. Algorithms – if the algorithm is well-known and widely used This doesn’t mean you can’t make dependencies out of these if you so choose.
  17. Real systems get a lot more complex than this. It’s not one place that will take a dependency, it’s a LOT of places.
  18. What we need is a way to centralize how these dependencies are created and injected. It would be awesome (in a way) if the “new” operator could be virtualized so we could just make the dependencies at the site of usage. But….how does one “new up” an interface? And how does that make it explicit what dependencies are needed by an object?
  19. Another thing devs will do is use a “service locator” pattern. There’s a global container defined that code knows about and resolves dependencies there. DON’T. It’s not explicit in terms of what dependencies are needed by a piece of code Testing in isolation is problematic – i.e. each test may need a different configuration setup, but if they’re run in parallel, issues will occur.
  20. So let’s use a container that will manage all the defined dependencies in an application. That’s the responsibility of an IoC container
  21. Containers should have the following three features: Register – set up all dependencies Resolve – get a dependency out of the container Release – manage disposable resources
  22. A small, useful-but-useless container.
  23. Now, we can reinvent the wheel, and just make one on our own. That’s what I’m going to do in the next demo, but keep in mind….you really shouldn’t do this. In fact this picture should be a warning that you shouldn’t spend the time doing it yourself, because mature containers do a lot more than just registering and resolving dependencies.
  24. A DIY container will only get you so far. There are a lot of things that you need to consider when you create an container – even this list doesn’t cover them all. Dependent objects should not care if the dependency is a singleton, is disposable, etc.
  25. Dependents should be as ignorant as possible about the dependency they’re given. They shouldn’t care if the parent would always be the same one for the lifetime of the app, or if
  26. Dependents should also be able to control the usage of a dependency – e.g. if the dependency isn’t always used, it should be able to specify that it’s a Lazy<>, even if the dependency wasn’t registered that way.
  27. Dependents should not care if the dependency is disposable. In fact, it can’t, as this example shows. But SOMEBODY has to care that it’s disposable.
  28. And there’s a LOT of containers out there than you can pick for .NET. There really is no reason to do it yourself, unless you’re either: Really interested to see if you can make one work You’re convinced you can do it better!
  29. Of course, which one you pick is really up to you. There’s no good reason to spend a significant amount of time – the most popular ones essentially do the same thing in their own ways. Fighting over a specific container isn’t worth the time.
  30. It’s like fighting over tabs or spaces. We all know tabs is correct, why waste that time? 
  31. My personal preference is Autofac. It’s very flexible and provides a lot of dependency management features that I find appealing. But again, if you use StructureMap, or Ninject, those will work just fine.
  32. There are great sites that have done a lot of performance investigations into each framework, so check them out and use that to guide your choice.
  33. So let’s see how we can use Autofac to register dependencies and resolve them using a Lazy<> and a Func<string, T>, where the former isn’t registered, but the latter is:
  34. Now, most of us aren’t writing console applications for production; other application hosts are used.
  35. Most modern hosts have integration points with NuGet packages that make it pretty simple to put your favorite IoC in play with the application.
  36. With WebApi, for example, there’s a DependencyResolver property on the GlobalConfiguration that you can set with an implementation of this interface….and that’s already done for you.
  37. Last demo: use Autofac with WebApi
  38. This sums it up well
  39. References * Inversion of Control Patterns for the Microsoft .NET Framework - https://visualstudiomagazine.com/articles/2010/08/01/inversion-of-control-patterns-for-the-microsoft-net-framework.aspx * List of .NET Dependency Injection Containers (IOC) - http://www.hanselman.com/blog/ListOfNETDependencyInjectionContainersIOC.aspx * IoC Container Benchmark - Performance comparison - http://www.palmmedia.de/Blog/2011/8/30/ioc-container-benchmark-performance-comparison * IoC Battle: http://www.iocbattle.com/ * Inversion of control containers – Best practices - http://www.dotnetcodegeeks.com/2012/05/inversion-of-control-containers-best.html * Building an IoC container in 15 lines of code - http://ayende.com/blog/2886/building-an-ioc-container-in-15-lines-of-code * Using IDisposable with Autofac - http://binarysculpting.com/2012/08/19/using-idisposable-with-autofac/