SlideShare ist ein Scribd-Unternehmen logo
1 von 30
The Zen of Inversion of
       Control




                     Christopher Fairbairn
                      ARANZ Medical Ltd
              christopher@christec.co.nz
                               www.christec.co.nz/blog/
A definition?

        “Inversion of Control, or IoC, is an
          abstract principle describing an
             aspect of some software
         architecture designs in which the
           flow of control of a system is
           inverted in comparison to the
            traditional architecture of
                 software libraries.”

                                        www.christec.co.nz/blog/
Complicating a simple idea




                             www.christec.co.nz/blog/
An improved definition?


       “Inversion of Control is a style of
         software construction where
      reusable, generic code controls the
      execution of problem-specific code
      with the strong connotation that
      the reusable code and the problem-
          specific code are developed
                 independently”
                                       www.christec.co.nz/blog/
An improved definition?

         “High-level modules should not
       depend on low-level modules. Both
        should depend on abstractions.”
                     Robert C. Martin .



                                       www.christec.co.nz/blog/
A worked example
 http://www.code-magazine.com/Article.aspx?quickid=0903101




Jon Stonecash


CODE magazine
March/April issue
                                                www.christec.co.nz/blog/
Code Demo


            Developing throw away code




            “It’s ok, this will never go into
                   production use…”.

                                       www.christec.co.nz/blog/
Code Demo


             Making it more flexible




             “It’s only one additional
            parameter. No harm done…”.

                                  www.christec.co.nz/blog/
A scalability problem?
•Can we only process files older than 5 days?
•Can we delete files rather than listing them?
•I want PDF files as well as XLS files.



                  “I can’t keep doing this for
                 every change in requirements…”.

                                          www.christec.co.nz/blog/
The Core Logic

 Enumerate over
 each file

   Compare to filter
   condition

      Process files that
      match
                           www.christec.co.nz/blog/
The Project Specific Logic



     What is the    What to do
       “filter”      with files
     condition?    that match?



                             www.christec.co.nz/blog/
Delegates

       “A delegate is a type defining a
     method signature, so that delegate
       instances can hold and invoke a
      method or list of methods that
            match its signature.”

        C# Language Pocket Reference

                                     www.christec.co.nz/blog/
Delegates
 An original C# 1.0 feature

 Define
 delegate int CalculationHandler(int a, int b);

 Construct
 CalculationHandler ch = new
     CalculationHandler(AddNumbers);

 Invoke
 int result = ch(1, 2);


                                       www.christec.co.nz/blog/
Delegates
 An original C# 1.0 feature

 Define
 delegate int CalculationHandler(int a, int b);

 Construct
 CalculationHandler ch = AddNumbers;


 Invoke
 int result = ch(1, 2);


                                       www.christec.co.nz/blog/
Delegates
 C# 2.0 introduced Anonymous Delegates

 Define
 delegate int CalculationHandler(int a, int b);

 Construct
 CalculationHandler ch =
       delegate(int a, int b){ return a + b; };

 Invoke
 int result = ch(1, 2);


                                       www.christec.co.nz/blog/
Code Demo


                  Inverting Control




              “My secret plan to allow my
            workmates to do the hard work”
                         
                                      www.christec.co.nz/blog/
Delegates
 C# 3.0 introduced Lambda Expressions

 Define
 delegate int CalculationHandler(int a, int b);

 Construct
 CalculationHandler ch = (a, b) => a + b;


 Invoke
 int result = ch(1, 2);


                                       www.christec.co.nz/blog/
.NET 3.5 BCL
The .NET 3.5 BCL introduces some common
delegate types


namespace System {
  delegate void Action<T>(T obj);
  delegate TResult Func<T, TResult>(T arg);
}

                                       www.christec.co.nz/blog/
Code Demo


            Reducing the amount of code




             “The less I need to type the
                    happier I’ll be…”.

                                   www.christec.co.nz/blog/
What have we achieved?
•Separation of Concerns
•Inversion of Control




               “But I’ve also made it harder for
                     my clients to use…”.

                                         www.christec.co.nz/blog/
IoC Containers


     “Dependency Injection refers to the
 process of automatically supplying an external
    dependency to a software component.

  It is a specific form of inversion of control
   where the concept being inverted is the
 process of obtaining the needed dependency.”
                                           www.christec.co.nz/blog/
IoC Containers
•Hashtable of interface vs
implementing type


•In its simplest form basically
  Dictionary<Type, Object>


•Lifecycle management etc

                                  www.christec.co.nz/blog/
Using Ninject
•Adding objects to the container
  •XML, Fluent, Database, Code…


• Bind<IFileFilter>().To<SomeClass>();

                  “IoC containers perform two
                     basic functions: putting
                 dependencies in and getting fully
                   constructed objects out…”.
                                         www.christec.co.nz/blog/
Using Ninject
•Instantiating objects via the Container
  •Constructor or Property Injection


•IFileFilter filter = kernel.Get<IFileFilter>();

                     “IoC containers perform two
                        basic functions: putting
                    dependencies in and getting fully
                      constructed objects out…”.
                                             www.christec.co.nz/blog/
Code Demo


             Dependency Injection with
                        Ninject


             “Hiding the complexity with
            another layer of indirection…”.

                                    www.christec.co.nz/blog/
IoC Advantages
•Ability to quickly reconfigure / repurpose
•Reduces hard dependencies between modules
•Centralises configuration




                                          www.christec.co.nz/blog/
A bridge too far?
•As with any technique this can be taken to
ill-logical extremes and beyond


•There are trade offs and gains with
  •Flexability
  •Maintainability
  •Understandability

                                       www.christec.co.nz/blog/
Find out more
Inversion of Control Containers and
the Dependency Injection Pattern -
Martin Fowler
http://martinfowler.com/articles/injection.html




Loosen Up: Tame Your Dependencies for More
Flexible Apps – James Kovacs
http://msdn.microsoft.com/en-us/magazine/cc337885.aspx
                                                  www.christec.co.nz/blog/
Find out more




                www.christec.co.nz/blog/
Contact Information
Christopher Fairbairn
ARANZ Medical Ltd




        Questions?
Email: christopher@christec.co.nz
Website: www.christec.co.nz/blog/
                                    www.christec.co.nz/blog/

Weitere ähnliche Inhalte

Was ist angesagt?

Techlunch - Dependency Injection with Vaadin
Techlunch - Dependency Injection with VaadinTechlunch - Dependency Injection with Vaadin
Techlunch - Dependency Injection with VaadinPeter Lehto
 
Building impressive layout systems with vaadin
Building impressive layout systems with vaadinBuilding impressive layout systems with vaadin
Building impressive layout systems with vaadinPeter Lehto
 
Vaadin with Java EE 7
Vaadin with Java EE 7Vaadin with Java EE 7
Vaadin with Java EE 7Peter Lehto
 
Unit Testing Documentum Foundation Classes Code
Unit Testing Documentum Foundation Classes CodeUnit Testing Documentum Foundation Classes Code
Unit Testing Documentum Foundation Classes CodeBlueFish
 
Vaadin 8 with Spring Framework
Vaadin 8 with Spring FrameworkVaadin 8 with Spring Framework
Vaadin 8 with Spring FrameworkPeter Lehto
 
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Theo Jungeblut
 
Vaadin DevDay 2017 - Data Binding in Vaadin 8
Vaadin DevDay 2017 - Data Binding in Vaadin 8Vaadin DevDay 2017 - Data Binding in Vaadin 8
Vaadin DevDay 2017 - Data Binding in Vaadin 8Peter Lehto
 
DevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation SlidesDevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation SlidesFab L
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorialAnh Quân
 
Vaadin 8 with Spring Frameworks AutoConfiguration
Vaadin 8 with Spring Frameworks AutoConfigurationVaadin 8 with Spring Frameworks AutoConfiguration
Vaadin 8 with Spring Frameworks AutoConfigurationPeter Lehto
 
Extending Java EE with CDI and JBoss Forge
Extending Java EE with CDI and JBoss ForgeExtending Java EE with CDI and JBoss Forge
Extending Java EE with CDI and JBoss ForgeAntoine Sabot-Durand
 
Agile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai ShevchenkoAgile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai ShevchenkoMoldova ICT Summit
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Deliverymasoodjan
 

Was ist angesagt? (16)

Techlunch - Dependency Injection with Vaadin
Techlunch - Dependency Injection with VaadinTechlunch - Dependency Injection with Vaadin
Techlunch - Dependency Injection with Vaadin
 
Building impressive layout systems with vaadin
Building impressive layout systems with vaadinBuilding impressive layout systems with vaadin
Building impressive layout systems with vaadin
 
Vaadin with Java EE 7
Vaadin with Java EE 7Vaadin with Java EE 7
Vaadin with Java EE 7
 
Unit Testing Documentum Foundation Classes Code
Unit Testing Documentum Foundation Classes CodeUnit Testing Documentum Foundation Classes Code
Unit Testing Documentum Foundation Classes Code
 
Vaadin 8 with Spring Framework
Vaadin 8 with Spring FrameworkVaadin 8 with Spring Framework
Vaadin 8 with Spring Framework
 
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
 
Let your tests drive your code
Let your tests drive your codeLet your tests drive your code
Let your tests drive your code
 
Vaadin DevDay 2017 - Data Binding in Vaadin 8
Vaadin DevDay 2017 - Data Binding in Vaadin 8Vaadin DevDay 2017 - Data Binding in Vaadin 8
Vaadin DevDay 2017 - Data Binding in Vaadin 8
 
DevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation SlidesDevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation Slides
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 
Vaadin 8 with Spring Frameworks AutoConfiguration
Vaadin 8 with Spring Frameworks AutoConfigurationVaadin 8 with Spring Frameworks AutoConfiguration
Vaadin 8 with Spring Frameworks AutoConfiguration
 
IoC and Mapper in C#
IoC and Mapper in C#IoC and Mapper in C#
IoC and Mapper in C#
 
Extending Java EE with CDI and JBoss Forge
Extending Java EE with CDI and JBoss ForgeExtending Java EE with CDI and JBoss Forge
Extending Java EE with CDI and JBoss Forge
 
Agile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai ShevchenkoAgile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai Shevchenko
 
Continuous deployment 2.0
Continuous deployment 2.0Continuous deployment 2.0
Continuous deployment 2.0
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Delivery
 

Andere mochten auch

Windows Mobile Development and MEDC 2007
Windows Mobile Development and MEDC 2007Windows Mobile Development and MEDC 2007
Windows Mobile Development and MEDC 2007christopherfairbairn
 
Compact Framework Development For The Desktop Developer
Compact Framework Development For The Desktop DeveloperCompact Framework Development For The Desktop Developer
Compact Framework Development For The Desktop Developerchristopherfairbairn
 
Introduction To .Net Compact Framework and SQL Server CE Development
Introduction To .Net Compact Framework and SQL Server CE DevelopmentIntroduction To .Net Compact Framework and SQL Server CE Development
Introduction To .Net Compact Framework and SQL Server CE Developmentchristopherfairbairn
 
Practical semantics - An introduction
Practical semantics - An introductionPractical semantics - An introduction
Practical semantics - An introductionBen Gardner
 
Enterprise wiki's: Does one size fit all?
Enterprise wiki's: Does one size fit all?Enterprise wiki's: Does one size fit all?
Enterprise wiki's: Does one size fit all?Ben Gardner
 
Kristina Smeriglio Writing Portfolio
Kristina Smeriglio Writing PortfolioKristina Smeriglio Writing Portfolio
Kristina Smeriglio Writing PortfolioKristina Smeriglio
 
Introduction to .NET Micro Framework Development
Introduction to .NET Micro Framework DevelopmentIntroduction to .NET Micro Framework Development
Introduction to .NET Micro Framework Developmentchristopherfairbairn
 
Leveraging Microsoft Embedded and Mobile Platforms
Leveraging Microsoft Embedded and Mobile PlatformsLeveraging Microsoft Embedded and Mobile Platforms
Leveraging Microsoft Embedded and Mobile Platformschristopherfairbairn
 
Translating Judaism Presentation To Brandeis V5
Translating Judaism Presentation To Brandeis V5Translating Judaism Presentation To Brandeis V5
Translating Judaism Presentation To Brandeis V5Ariel Beery
 
Asher Epstein at Presentense 2008
Asher Epstein at Presentense 2008Asher Epstein at Presentense 2008
Asher Epstein at Presentense 2008Ariel Beery
 
Post Digital Horizons Presentation From Invest In Value Roadtrip 2007
Post  Digital  Horizons  Presentation From  Invest In  Value  Roadtrip 2007Post  Digital  Horizons  Presentation From  Invest In  Value  Roadtrip 2007
Post Digital Horizons Presentation From Invest In Value Roadtrip 2007Ariel Beery
 
Cargo Port - Stripping & Stuffing Operations
Cargo Port - Stripping & Stuffing OperationsCargo Port - Stripping & Stuffing Operations
Cargo Port - Stripping & Stuffing Operationsluccastera
 
Translating Judaism Presentation To Brandeis v4
Translating Judaism Presentation To Brandeis v4Translating Judaism Presentation To Brandeis v4
Translating Judaism Presentation To Brandeis v4Ariel Beery
 
Picz Presentation General V2
Picz Presentation General V2Picz Presentation General V2
Picz Presentation General V2Ariel Beery
 
Vision Presentation For Creative Zionist Network - 3 minute version
Vision  Presentation For Creative  Zionist  Network - 3 minute versionVision  Presentation For Creative  Zionist  Network - 3 minute version
Vision Presentation For Creative Zionist Network - 3 minute versionAriel Beery
 

Andere mochten auch (20)

C# 1.0 features lighting talk
C# 1.0 features lighting talkC# 1.0 features lighting talk
C# 1.0 features lighting talk
 
Python - A Mobile Perspective
Python - A Mobile PerspectivePython - A Mobile Perspective
Python - A Mobile Perspective
 
Windows Mobile Development and MEDC 2007
Windows Mobile Development and MEDC 2007Windows Mobile Development and MEDC 2007
Windows Mobile Development and MEDC 2007
 
Compact Framework Development For The Desktop Developer
Compact Framework Development For The Desktop DeveloperCompact Framework Development For The Desktop Developer
Compact Framework Development For The Desktop Developer
 
Introduction To .Net Compact Framework and SQL Server CE Development
Introduction To .Net Compact Framework and SQL Server CE DevelopmentIntroduction To .Net Compact Framework and SQL Server CE Development
Introduction To .Net Compact Framework and SQL Server CE Development
 
Funny Toilet
Funny ToiletFunny Toilet
Funny Toilet
 
Practical semantics - An introduction
Practical semantics - An introductionPractical semantics - An introduction
Practical semantics - An introduction
 
Enterprise wiki's: Does one size fit all?
Enterprise wiki's: Does one size fit all?Enterprise wiki's: Does one size fit all?
Enterprise wiki's: Does one size fit all?
 
Kristina Smeriglio Writing Portfolio
Kristina Smeriglio Writing PortfolioKristina Smeriglio Writing Portfolio
Kristina Smeriglio Writing Portfolio
 
Introduction to .NET Micro Framework Development
Introduction to .NET Micro Framework DevelopmentIntroduction to .NET Micro Framework Development
Introduction to .NET Micro Framework Development
 
meet Jessica
meet Jessicameet Jessica
meet Jessica
 
Leveraging Microsoft Embedded and Mobile Platforms
Leveraging Microsoft Embedded and Mobile PlatformsLeveraging Microsoft Embedded and Mobile Platforms
Leveraging Microsoft Embedded and Mobile Platforms
 
Translating Judaism Presentation To Brandeis V5
Translating Judaism Presentation To Brandeis V5Translating Judaism Presentation To Brandeis V5
Translating Judaism Presentation To Brandeis V5
 
Asher Epstein at Presentense 2008
Asher Epstein at Presentense 2008Asher Epstein at Presentense 2008
Asher Epstein at Presentense 2008
 
Post Digital Horizons Presentation From Invest In Value Roadtrip 2007
Post  Digital  Horizons  Presentation From  Invest In  Value  Roadtrip 2007Post  Digital  Horizons  Presentation From  Invest In  Value  Roadtrip 2007
Post Digital Horizons Presentation From Invest In Value Roadtrip 2007
 
Cargo Port - Stripping & Stuffing Operations
Cargo Port - Stripping & Stuffing OperationsCargo Port - Stripping & Stuffing Operations
Cargo Port - Stripping & Stuffing Operations
 
Translating Judaism Presentation To Brandeis v4
Translating Judaism Presentation To Brandeis v4Translating Judaism Presentation To Brandeis v4
Translating Judaism Presentation To Brandeis v4
 
Power02
Power02Power02
Power02
 
Picz Presentation General V2
Picz Presentation General V2Picz Presentation General V2
Picz Presentation General V2
 
Vision Presentation For Creative Zionist Network - 3 minute version
Vision  Presentation For Creative  Zionist  Network - 3 minute versionVision  Presentation For Creative  Zionist  Network - 3 minute version
Vision Presentation For Creative Zionist Network - 3 minute version
 

Ähnlich wie The Zen of Inversion of Control

Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckTheo Jungeblut
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Theo Jungeblut
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampTheo Jungeblut
 
Ultimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on KubernetesUltimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on Kuberneteskloia
 
Micronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureZachary Klein
 
Code instrumentation
Code instrumentationCode instrumentation
Code instrumentationMennan Tekbir
 
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)Theo Jungeblut
 
Clean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code CampClean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code CampTheo Jungeblut
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 
generate IP CORES
generate IP CORESgenerate IP CORES
generate IP CORESguest296013
 
Design by contract
Design by contractDesign by contract
Design by contractJiří Kiml
 
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...JSFestUA
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency InjectionTheo Jungeblut
 
CI/CD Pipeline with Kubernetes
CI/CD Pipeline with KubernetesCI/CD Pipeline with Kubernetes
CI/CD Pipeline with KubernetesMukesh Singh
 
George Thiruvathukal, User Experiences with Plone Content Management
George Thiruvathukal, User Experiences with Plone Content Management George Thiruvathukal, User Experiences with Plone Content Management
George Thiruvathukal, User Experiences with Plone Content Management webcontent2007
 
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...DevSecCon
 
Reactive summit 2020 microsoft orleans the easy way
Reactive summit 2020   microsoft orleans the easy wayReactive summit 2020   microsoft orleans the easy way
Reactive summit 2020 microsoft orleans the easy wayJohn Azariah
 
Polaris presentation ioc - code conference
Polaris presentation   ioc - code conferencePolaris presentation   ioc - code conference
Polaris presentation ioc - code conferenceSteven Contos
 

Ähnlich wie The Zen of Inversion of Control (20)

Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
 
Ultimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on KubernetesUltimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on Kubernetes
 
Micronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro Future
 
Code instrumentation
Code instrumentationCode instrumentation
Code instrumentation
 
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
 
Clean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code CampClean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code Camp
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
generate IP CORES
generate IP CORESgenerate IP CORES
generate IP CORES
 
Design by contract
Design by contractDesign by contract
Design by contract
 
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
 
CI
CICI
CI
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
 
CI/CD Pipeline with Kubernetes
CI/CD Pipeline with KubernetesCI/CD Pipeline with Kubernetes
CI/CD Pipeline with Kubernetes
 
George Thiruvathukal, User Experiences with Plone Content Management
George Thiruvathukal, User Experiences with Plone Content Management George Thiruvathukal, User Experiences with Plone Content Management
George Thiruvathukal, User Experiences with Plone Content Management
 
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
 
Reactive summit 2020 microsoft orleans the easy way
Reactive summit 2020   microsoft orleans the easy wayReactive summit 2020   microsoft orleans the easy way
Reactive summit 2020 microsoft orleans the easy way
 
Polaris presentation ioc - code conference
Polaris presentation   ioc - code conferencePolaris presentation   ioc - code conference
Polaris presentation ioc - code conference
 

Kürzlich hochgeladen

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Kürzlich hochgeladen (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

The Zen of Inversion of Control

  • 1. The Zen of Inversion of Control Christopher Fairbairn ARANZ Medical Ltd christopher@christec.co.nz www.christec.co.nz/blog/
  • 2. A definition? “Inversion of Control, or IoC, is an abstract principle describing an aspect of some software architecture designs in which the flow of control of a system is inverted in comparison to the traditional architecture of software libraries.” www.christec.co.nz/blog/
  • 3. Complicating a simple idea www.christec.co.nz/blog/
  • 4. An improved definition? “Inversion of Control is a style of software construction where reusable, generic code controls the execution of problem-specific code with the strong connotation that the reusable code and the problem- specific code are developed independently” www.christec.co.nz/blog/
  • 5. An improved definition? “High-level modules should not depend on low-level modules. Both should depend on abstractions.” Robert C. Martin . www.christec.co.nz/blog/
  • 6. A worked example http://www.code-magazine.com/Article.aspx?quickid=0903101 Jon Stonecash CODE magazine March/April issue www.christec.co.nz/blog/
  • 7. Code Demo Developing throw away code “It’s ok, this will never go into production use…”. www.christec.co.nz/blog/
  • 8. Code Demo Making it more flexible “It’s only one additional parameter. No harm done…”. www.christec.co.nz/blog/
  • 9. A scalability problem? •Can we only process files older than 5 days? •Can we delete files rather than listing them? •I want PDF files as well as XLS files. “I can’t keep doing this for every change in requirements…”. www.christec.co.nz/blog/
  • 10. The Core Logic Enumerate over each file Compare to filter condition Process files that match www.christec.co.nz/blog/
  • 11. The Project Specific Logic What is the What to do “filter” with files condition? that match? www.christec.co.nz/blog/
  • 12. Delegates “A delegate is a type defining a method signature, so that delegate instances can hold and invoke a method or list of methods that match its signature.” C# Language Pocket Reference www.christec.co.nz/blog/
  • 13. Delegates An original C# 1.0 feature Define delegate int CalculationHandler(int a, int b); Construct CalculationHandler ch = new CalculationHandler(AddNumbers); Invoke int result = ch(1, 2); www.christec.co.nz/blog/
  • 14. Delegates An original C# 1.0 feature Define delegate int CalculationHandler(int a, int b); Construct CalculationHandler ch = AddNumbers; Invoke int result = ch(1, 2); www.christec.co.nz/blog/
  • 15. Delegates C# 2.0 introduced Anonymous Delegates Define delegate int CalculationHandler(int a, int b); Construct CalculationHandler ch = delegate(int a, int b){ return a + b; }; Invoke int result = ch(1, 2); www.christec.co.nz/blog/
  • 16. Code Demo Inverting Control “My secret plan to allow my workmates to do the hard work”  www.christec.co.nz/blog/
  • 17. Delegates C# 3.0 introduced Lambda Expressions Define delegate int CalculationHandler(int a, int b); Construct CalculationHandler ch = (a, b) => a + b; Invoke int result = ch(1, 2); www.christec.co.nz/blog/
  • 18. .NET 3.5 BCL The .NET 3.5 BCL introduces some common delegate types namespace System { delegate void Action<T>(T obj); delegate TResult Func<T, TResult>(T arg); } www.christec.co.nz/blog/
  • 19. Code Demo Reducing the amount of code “The less I need to type the happier I’ll be…”. www.christec.co.nz/blog/
  • 20. What have we achieved? •Separation of Concerns •Inversion of Control “But I’ve also made it harder for my clients to use…”. www.christec.co.nz/blog/
  • 21. IoC Containers “Dependency Injection refers to the process of automatically supplying an external dependency to a software component. It is a specific form of inversion of control where the concept being inverted is the process of obtaining the needed dependency.” www.christec.co.nz/blog/
  • 22. IoC Containers •Hashtable of interface vs implementing type •In its simplest form basically Dictionary<Type, Object> •Lifecycle management etc www.christec.co.nz/blog/
  • 23. Using Ninject •Adding objects to the container •XML, Fluent, Database, Code… • Bind<IFileFilter>().To<SomeClass>(); “IoC containers perform two basic functions: putting dependencies in and getting fully constructed objects out…”. www.christec.co.nz/blog/
  • 24. Using Ninject •Instantiating objects via the Container •Constructor or Property Injection •IFileFilter filter = kernel.Get<IFileFilter>(); “IoC containers perform two basic functions: putting dependencies in and getting fully constructed objects out…”. www.christec.co.nz/blog/
  • 25. Code Demo Dependency Injection with Ninject “Hiding the complexity with another layer of indirection…”. www.christec.co.nz/blog/
  • 26. IoC Advantages •Ability to quickly reconfigure / repurpose •Reduces hard dependencies between modules •Centralises configuration www.christec.co.nz/blog/
  • 27. A bridge too far? •As with any technique this can be taken to ill-logical extremes and beyond •There are trade offs and gains with •Flexability •Maintainability •Understandability www.christec.co.nz/blog/
  • 28. Find out more Inversion of Control Containers and the Dependency Injection Pattern - Martin Fowler http://martinfowler.com/articles/injection.html Loosen Up: Tame Your Dependencies for More Flexible Apps – James Kovacs http://msdn.microsoft.com/en-us/magazine/cc337885.aspx www.christec.co.nz/blog/
  • 29. Find out more www.christec.co.nz/blog/
  • 30. Contact Information Christopher Fairbairn ARANZ Medical Ltd Questions? Email: christopher@christec.co.nz Website: www.christec.co.nz/blog/ www.christec.co.nz/blog/

Hinweis der Redaktion

  1. <number>
  2. <number>
  3. <number>
  4. <number>
  5. <number>
  6. <number>
  7. <number>
  8. <number>
  9. <number>
  10. <number>
  11. <number>
  12. <number>
  13. <number>
  14. <number>
  15. Preaching to the “converted”Small EfficientPopular!<number>
  16. <number>
  17. <number>
  18. <number>
  19. <number>
  20. <number>
  21. <number>
  22. <number>
  23. <number>
  24. <number>
  25. <number>
  26. <number>
  27. <number>
  28. <number>