SlideShare a Scribd company logo
1 of 31
Download to read offline
Opinions and emotions
DUTDIP
Interesting Go nuances & My Mistakes
Abstractions over Implementations
Inject or Lookup Dependencies
Lifecycle of Services and Dependencies
Loose Coupling & Unit Testing
Avoid Unutilized Dependencies
Code against interfaces
Contracts & Data Model in a “model” package
Ben Johnson’s “Root” package
No cyclical dependencies
References:
https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1
https://appliedgo.net/di/
https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html
Credit:
Robert Wechsler (www.robertwechsler.com) for permission to use image of “Circular
Bike”.
Contracts to be implemented
Service has a Dependency
Sometimes, it also has Another-Dependency
Package-Level-New-Function (PLNF) for Service
Consume Dependency from the instance member
Typical Service initialization and invocation
Pass problem of implementations to Upper Layer
Tight coupling, Upper Layer needs to “know”
Pass from top (main) package to that
specific layer
Dependencies before Services
Validation & Persistence example
Why incur cost and allocate resources for unused dependencies?
Pass New Function
Func type in Model Package
Function not Instance
New Instance then Invoke
https://martinfowler.com/articles/injection.html#UsingAServiceLocator
Projects evolve, Requirements change
Signature of “New” function can change
Context class
Cant embed Functions in a Structure
(Language feature request)
Wrapper Method to a private member
Instantiate a Service, Invoke Operations
Code is a bit tedious
Func types -> Package Level New Functions
Orchestration, Package Level Variables
Encapsulate to Structures
Structure changes are backward compatible
Hide behind Interfaces
Flexibility and Extensibility
Reference:
● https://dave.cheney.net/2017/06/11/go-without-package-scoped-variables
Dependency New Function -> Dependency Factory Structure
Interface
Embed multiple Factories -> Super Factory
No wrapper code
Interface
Service expects Super Factory
Invoke
Add Service to Super Factory
Uniform invocation mechanism
SuperFactory is parameter
Pass SF to all Layers
Global Reference to SuperFactory in Model package
Initialize Service
Initialize Dependency
No Injection, Only Lookup
Defer language syntax
Unit Testing using GoMock
Create a Test Super Factory
Can also embed other relevant data structures
Initialize a Test-SF
Change my Factory implementation
Create a Singleton
Replace Embedding
Embed multiple structures
Almost like Multiple Inheritance
Can’t do it in Java or C#
No wrapper Code
Many services & dependencies, centralization
Changes in dependencies
Extreme loose coupling, Unit Testing
• Package level New Functions
• Pass Dependencies, Simple
• Assign functions to Package Variables
• Overwrite variables with Mock
• Same benefits and limitations
• Graph / Container
• Definitions, Resolve
• Reflection, Casting, Tighty coupling to variable
• Duck Typing
• Violation of Dependency Inversion principle
References:
● Package New Function
○ https://appliedgo.net/di/
○ https://medium.com/@zach_4342/dependency-injection-in-golang-
e587c69478a8
○ http://www.florinpatan.ro/2016/09/using-dependency-injection-pattern-
in-go.html
● Graphs & Containers
○ github.com/facebookgo/inject
○ github.com/karlkfi/inject
○ github.com/sarulabs/di
○ github.com/uber-go/dig
● Duck Typing
○ http://txt.fliglio.com/2015/04/di-duck-typing-and-clean-code-in-go/
● New Functions Assigned to Variables:
○ http://openmymind.net/Dependency-Injection-In-Go/
○ https://dave.cheney.net/2017/06/11/go-without-package-scoped-
variables
Super Factory contains many items
Restrict access to only the relevant factories
Create a custom factory interface,
Inherently compatible with SuperFactory

More Related Content

Similar to DUTDIP - Don't Use This Dependency Injection

Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationStephen Fuqua
 
2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the TrenchesNicolas Fränkel
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Kevin Schultz
 
20080531 Intro To Dependency Injection & Inversion Of Control
20080531 Intro To Dependency Injection & Inversion Of Control20080531 Intro To Dependency Injection & Inversion Of Control
20080531 Intro To Dependency Injection & Inversion Of Controldonnfelker
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build PipelineSamuel Brown
 
Extensibility - Software That Survives - Miguel A. Castro
Extensibility - Software That Survives - Miguel A. CastroExtensibility - Software That Survives - Miguel A. Castro
Extensibility - Software That Survives - Miguel A. CastroMohammad Tayseer
 
201502 - Integration Testing
201502 - Integration Testing201502 - Integration Testing
201502 - Integration Testinglyonjug
 
Patterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPatterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPhil Leggetter
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondSteve Westgarth
 
How to ace your .NET technical interview :: .Net Technical Check Tuneup
How to ace your .NET technical interview :: .Net Technical Check TuneupHow to ace your .NET technical interview :: .Net Technical Check Tuneup
How to ace your .NET technical interview :: .Net Technical Check TuneupBala Subra
 
Design patterns fast track
Design patterns fast trackDesign patterns fast track
Design patterns fast trackBinu Bhasuran
 
PHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersAdam Englander
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing SoftwareSteven Smith
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mockingmrjawright
 
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdfsiemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdfssuser1c8ca21
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 

Similar to DUTDIP - Don't Use This Dependency Injection (20)

Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test Automation
 
J2EE pattern 5
J2EE pattern 5J2EE pattern 5
J2EE pattern 5
 
2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)
 
20080531 Intro To Dependency Injection & Inversion Of Control
20080531 Intro To Dependency Injection & Inversion Of Control20080531 Intro To Dependency Injection & Inversion Of Control
20080531 Intro To Dependency Injection & Inversion Of Control
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build Pipeline
 
Extensibility - Software That Survives - Miguel A. Castro
Extensibility - Software That Survives - Miguel A. CastroExtensibility - Software That Survives - Miguel A. Castro
Extensibility - Software That Survives - Miguel A. Castro
 
201502 - Integration Testing
201502 - Integration Testing201502 - Integration Testing
201502 - Integration Testing
 
Patterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPatterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 apps
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and Beyond
 
How to ace your .NET technical interview :: .Net Technical Check Tuneup
How to ace your .NET technical interview :: .Net Technical Check TuneupHow to ace your .NET technical interview :: .Net Technical Check Tuneup
How to ace your .NET technical interview :: .Net Technical Check Tuneup
 
Design patterns fast track
Design patterns fast trackDesign patterns fast track
Design patterns fast track
 
PHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for Beginners
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing Software
 
Component library
Component libraryComponent library
Component library
 
Design pattern
Design patternDesign pattern
Design pattern
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mocking
 
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdfsiemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 

Recently uploaded

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
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
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
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
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
 
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 Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
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
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Recently uploaded (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
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
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
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
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
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...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
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...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

DUTDIP - Don't Use This Dependency Injection

  • 1.
  • 2. Opinions and emotions DUTDIP Interesting Go nuances & My Mistakes
  • 3. Abstractions over Implementations Inject or Lookup Dependencies Lifecycle of Services and Dependencies Loose Coupling & Unit Testing Avoid Unutilized Dependencies
  • 4. Code against interfaces Contracts & Data Model in a “model” package Ben Johnson’s “Root” package No cyclical dependencies References: https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1 https://appliedgo.net/di/ https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html Credit: Robert Wechsler (www.robertwechsler.com) for permission to use image of “Circular Bike”.
  • 5. Contracts to be implemented Service has a Dependency Sometimes, it also has Another-Dependency
  • 6. Package-Level-New-Function (PLNF) for Service Consume Dependency from the instance member Typical Service initialization and invocation
  • 7. Pass problem of implementations to Upper Layer Tight coupling, Upper Layer needs to “know”
  • 8. Pass from top (main) package to that specific layer
  • 9. Dependencies before Services Validation & Persistence example Why incur cost and allocate resources for unused dependencies?
  • 10. Pass New Function Func type in Model Package Function not Instance New Instance then Invoke https://martinfowler.com/articles/injection.html#UsingAServiceLocator
  • 11. Projects evolve, Requirements change Signature of “New” function can change Context class
  • 12. Cant embed Functions in a Structure (Language feature request) Wrapper Method to a private member
  • 13. Instantiate a Service, Invoke Operations Code is a bit tedious
  • 14. Func types -> Package Level New Functions Orchestration, Package Level Variables Encapsulate to Structures Structure changes are backward compatible Hide behind Interfaces Flexibility and Extensibility Reference: ● https://dave.cheney.net/2017/06/11/go-without-package-scoped-variables
  • 15. Dependency New Function -> Dependency Factory Structure Interface
  • 16. Embed multiple Factories -> Super Factory No wrapper code Interface
  • 17. Service expects Super Factory Invoke
  • 18. Add Service to Super Factory Uniform invocation mechanism SuperFactory is parameter Pass SF to all Layers
  • 19. Global Reference to SuperFactory in Model package Initialize Service Initialize Dependency
  • 20. No Injection, Only Lookup Defer language syntax
  • 21. Unit Testing using GoMock Create a Test Super Factory Can also embed other relevant data structures Initialize a Test-SF
  • 22.
  • 23. Change my Factory implementation Create a Singleton Replace Embedding
  • 24. Embed multiple structures Almost like Multiple Inheritance Can’t do it in Java or C# No wrapper Code
  • 25.
  • 26.
  • 27.
  • 28. Many services & dependencies, centralization Changes in dependencies Extreme loose coupling, Unit Testing
  • 29. • Package level New Functions • Pass Dependencies, Simple • Assign functions to Package Variables • Overwrite variables with Mock • Same benefits and limitations • Graph / Container • Definitions, Resolve • Reflection, Casting, Tighty coupling to variable • Duck Typing • Violation of Dependency Inversion principle References: ● Package New Function ○ https://appliedgo.net/di/ ○ https://medium.com/@zach_4342/dependency-injection-in-golang- e587c69478a8 ○ http://www.florinpatan.ro/2016/09/using-dependency-injection-pattern-
  • 30. in-go.html ● Graphs & Containers ○ github.com/facebookgo/inject ○ github.com/karlkfi/inject ○ github.com/sarulabs/di ○ github.com/uber-go/dig ● Duck Typing ○ http://txt.fliglio.com/2015/04/di-duck-typing-and-clean-code-in-go/ ● New Functions Assigned to Variables: ○ http://openmymind.net/Dependency-Injection-In-Go/ ○ https://dave.cheney.net/2017/06/11/go-without-package-scoped- variables
  • 31. Super Factory contains many items Restrict access to only the relevant factories Create a custom factory interface, Inherently compatible with SuperFactory