SlideShare a Scribd company logo
…and you: So happy together 
 Here’s the absolute worst explanation ever:
 ”Instead of newing up objects, you just call ‘container.resolve’”
 With the definition of, “just call container.Resolve instead of newing an
object up”, when you go to a job interview and whiteboard some pseudo-
code, they might say something like:
Pretty sure this
guy voted ‘NO’
on hiring me…
 Merriam Webster Dictionary: “something that is dependent on something else”
 For example: “A time-traveling DeLorean’s dependency on plutonium was a real
problem in 1955.”
 Wikipedia’s definition relative to computer science: “[A dependency is a] coupling,
a state in which one object uses a function of another object.”
 For example: My app needs to make calls to a web service to get and store data, so my
business logic has a dependency on the web service.
 When you have a “coupling” of two classes, a loose coupling is the way to go in order to
make your code more testable and maintainable for the future.
 3 common types of dependency injection:
 Setter Injection
 Dependencies are injected through specific property setters. I have never seen this in the wild.
 Interface Injection
 Classes with dependencies implement an interface that exposes a setter method, and
dependencies use this to inject themselves into any class passed to it. I have never seen this in
the wild.
 Constructor Injection
 Yaaaaaaay! Winner winner!! Dependencies are injected through the class constructor. This is the
only method I’ve seen in the wild.
Interface: A
contract or
specification
Concrete
implementation of
the interface
 We want ALL of our dependencies to be based on an interface.
 Any service code you write should have an interface. Other classes in your app
will rely only on the interface… Not the “concrete” implementation of the
interface.
 You will definitely run into situations where some 3rd party code does not provide
an interface (Microsoft’s HttpClient class, as a ubiquitous for-instance).
 Never give up… Never surrender! There are ways to create wrappers for such classes
which keep the vast majority of your code testable and loosely coupled. True story!
 Before DI  After DI
 You’ll notice you use the “new”
keyword a WHOLE lot less when
using Dependency Injection.
 When I finally learned how to use dependency injection, I still had no clue WHY
we were using it. All I knew was that some highly paid consultants said to do it,
and that was that.
 The two most important reasons to use “DI” (Dependency Injection):
 Makes it super-mega-monster-easy to unit test code without insanely complicated
setups.
 Caveat: As long as you learn how to use mocks when unit testing. On Luxor, we use MOQ, which
I would absolutely recommend.
 Another popular mocking framework for .NET: NSubstitute
 Promotes writing code where various services (aka ‘dependencies’) your code requires
can be loosely coupled with your code.
 The container is at the very heart of your DI implementation.
 Interfaces are mapped to concrete types, so that the container can provide the
correct implementation when an interface is requested.
 Containers typically allow you to specify the “lifetime” of any object it knows
about. You can have a singleton, one instance per thread, and more.
 Containers map views to viewModels in the MVVM design pattern (used in UWP,
WPF, and Xamarin.Forms apps, for example).
 The container is the thing that will new up all of your services, views, and
viewModels as they are needed.
 The magic: When you need some service in a class, you just add the interface to
its constructor, and the container magically will provide it!
 No… SERIOUSLY. It’s kind of amazing!!
 How does the
container know what
concrete types to
provide for your
interfaces?
 How does the
container know which
views go with which
viewModels?
 Answer:
Registration!
 Notice that ALL of the constructor parameters are interface types.
 When we discover we need a new service, we can just add it to the constructor,
and our DI container takes care of injecting it (thanks to the registration).
 Note: Yes, there might be a code smell of too many dependencies in this ViewModel, but
that’s not important right now. 
 The ViewModel from the previous slide has SEVEN dependencies. That would be
a TON of overhead if they were all concrete classes, and LOTS of integration
concerns to worry about when it came to testing!
 Instead, we just mock, mock, mock all our problems away!
Arrange
Act
Assert
 Infinitely easier (and possible!) unit testing of code.
 Loosely coupled software.
 While DI is complex, the alternative is even MORE complex!
 Just ask for whatever services you want in a constructor, and your DI container
will “make it so”!
 No complications about whether a class is a singleton or not… You already took
care of that when you registered the class with the container.
 As long as the container knows about the interface and the concrete class you
want to implement it with, you’re all set.
 Swap out implementations of interfaces (demo mode, anyone??).
Dependency Injection Lightning Talk

More Related Content

Similar to Dependency Injection Lightning Talk

Introduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning SimpleIntroduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning Simple
Sandeep Hijam
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
RookieOne
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
meghantaylor
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Tracy Clark
 
Introduction to dependency injection in Scala (Play)
Introduction to dependency injection in Scala (Play)Introduction to dependency injection in Scala (Play)
Introduction to dependency injection in Scala (Play)
Knoldus Inc.
 
C# interview
C# interviewC# interview
C# interview
ajeesharakkal
 
The Taming Of The Code
The Taming Of The CodeThe Taming Of The Code
The Taming Of The Code
Alan Stevens
 
Swiz DAO
Swiz DAOSwiz DAO
Swiz DAO
devaraj ns
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Bill Buchan
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
Jared Faris
 
Devops interview questions 1 www.bigclasses.com
Devops interview questions  1  www.bigclasses.comDevops interview questions  1  www.bigclasses.com
Devops interview questions 1 www.bigclasses.com
bigclasses.com
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
Eric Selje
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
Pablo Villar
 
DevOne - How to not fail with Azure
DevOne - How to not fail with AzureDevOne - How to not fail with Azure
DevOne - How to not fail with Azure
Martin Gutenbrunner
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
Naresh Jain
 
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
Enea Gabriel
 
Spring IOC
Spring IOCSpring IOC
Spring IOC
SNEHAL MASNE
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class Design
James Phillips
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit Testing
James Phillips
 
So Many Frameworks, So Little Time
So Many Frameworks, So Little TimeSo Many Frameworks, So Little Time
So Many Frameworks, So Little Time
Richard Lord
 

Similar to Dependency Injection Lightning Talk (20)

Introduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning SimpleIntroduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning Simple
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Introduction to dependency injection in Scala (Play)
Introduction to dependency injection in Scala (Play)Introduction to dependency injection in Scala (Play)
Introduction to dependency injection in Scala (Play)
 
C# interview
C# interviewC# interview
C# interview
 
The Taming Of The Code
The Taming Of The CodeThe Taming Of The Code
The Taming Of The Code
 
Swiz DAO
Swiz DAOSwiz DAO
Swiz DAO
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
 
Devops interview questions 1 www.bigclasses.com
Devops interview questions  1  www.bigclasses.comDevops interview questions  1  www.bigclasses.com
Devops interview questions 1 www.bigclasses.com
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 
DevOne - How to not fail with Azure
DevOne - How to not fail with AzureDevOne - How to not fail with Azure
DevOne - How to not fail with Azure
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
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
 
Spring IOC
Spring IOCSpring IOC
Spring IOC
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class Design
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit Testing
 
So Many Frameworks, So Little Time
So Many Frameworks, So Little TimeSo Many Frameworks, So Little Time
So Many Frameworks, So Little Time
 

Recently uploaded

Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 

Recently uploaded (20)

Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 

Dependency Injection Lightning Talk

  • 1. …and you: So happy together 
  • 2.  Here’s the absolute worst explanation ever:  ”Instead of newing up objects, you just call ‘container.resolve’”
  • 3.  With the definition of, “just call container.Resolve instead of newing an object up”, when you go to a job interview and whiteboard some pseudo- code, they might say something like: Pretty sure this guy voted ‘NO’ on hiring me…
  • 4.  Merriam Webster Dictionary: “something that is dependent on something else”  For example: “A time-traveling DeLorean’s dependency on plutonium was a real problem in 1955.”  Wikipedia’s definition relative to computer science: “[A dependency is a] coupling, a state in which one object uses a function of another object.”  For example: My app needs to make calls to a web service to get and store data, so my business logic has a dependency on the web service.  When you have a “coupling” of two classes, a loose coupling is the way to go in order to make your code more testable and maintainable for the future.
  • 5.  3 common types of dependency injection:  Setter Injection  Dependencies are injected through specific property setters. I have never seen this in the wild.  Interface Injection  Classes with dependencies implement an interface that exposes a setter method, and dependencies use this to inject themselves into any class passed to it. I have never seen this in the wild.  Constructor Injection  Yaaaaaaay! Winner winner!! Dependencies are injected through the class constructor. This is the only method I’ve seen in the wild.
  • 7.  We want ALL of our dependencies to be based on an interface.  Any service code you write should have an interface. Other classes in your app will rely only on the interface… Not the “concrete” implementation of the interface.  You will definitely run into situations where some 3rd party code does not provide an interface (Microsoft’s HttpClient class, as a ubiquitous for-instance).  Never give up… Never surrender! There are ways to create wrappers for such classes which keep the vast majority of your code testable and loosely coupled. True story!
  • 8.  Before DI  After DI  You’ll notice you use the “new” keyword a WHOLE lot less when using Dependency Injection.
  • 9.  When I finally learned how to use dependency injection, I still had no clue WHY we were using it. All I knew was that some highly paid consultants said to do it, and that was that.  The two most important reasons to use “DI” (Dependency Injection):  Makes it super-mega-monster-easy to unit test code without insanely complicated setups.  Caveat: As long as you learn how to use mocks when unit testing. On Luxor, we use MOQ, which I would absolutely recommend.  Another popular mocking framework for .NET: NSubstitute  Promotes writing code where various services (aka ‘dependencies’) your code requires can be loosely coupled with your code.
  • 10.  The container is at the very heart of your DI implementation.  Interfaces are mapped to concrete types, so that the container can provide the correct implementation when an interface is requested.  Containers typically allow you to specify the “lifetime” of any object it knows about. You can have a singleton, one instance per thread, and more.  Containers map views to viewModels in the MVVM design pattern (used in UWP, WPF, and Xamarin.Forms apps, for example).  The container is the thing that will new up all of your services, views, and viewModels as they are needed.
  • 11.  The magic: When you need some service in a class, you just add the interface to its constructor, and the container magically will provide it!  No… SERIOUSLY. It’s kind of amazing!!
  • 12.  How does the container know what concrete types to provide for your interfaces?  How does the container know which views go with which viewModels?  Answer: Registration!
  • 13.  Notice that ALL of the constructor parameters are interface types.  When we discover we need a new service, we can just add it to the constructor, and our DI container takes care of injecting it (thanks to the registration).  Note: Yes, there might be a code smell of too many dependencies in this ViewModel, but that’s not important right now. 
  • 14.  The ViewModel from the previous slide has SEVEN dependencies. That would be a TON of overhead if they were all concrete classes, and LOTS of integration concerns to worry about when it came to testing!  Instead, we just mock, mock, mock all our problems away!
  • 16.  Infinitely easier (and possible!) unit testing of code.  Loosely coupled software.  While DI is complex, the alternative is even MORE complex!  Just ask for whatever services you want in a constructor, and your DI container will “make it so”!  No complications about whether a class is a singleton or not… You already took care of that when you registered the class with the container.  As long as the container knows about the interface and the concrete class you want to implement it with, you’re all set.  Swap out implementations of interfaces (demo mode, anyone??).