SlideShare a Scribd company logo
DUTDIP - Don't Use This Dependency Injection
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
DUTDIP - Don't Use This Dependency Injection
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
DUTDIP - Don't Use This Dependency Injection
DUTDIP - Don't Use This Dependency Injection
DUTDIP - Don't Use This Dependency Injection
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

PPTX
Jbehave- Basics to Advance
PPT
Test Driven Development using QUnit
PDF
Testing ansible roles with molecule
PPT
Inside ASP.NET MVC framework
PPT
Inside asp.net mvc framework
PPTX
JMeter Database Performace Testing - Keytorc Approach
ODP
Integration Testing in Python
PPTX
Apex Testing and Best Practices
Jbehave- Basics to Advance
Test Driven Development using QUnit
Testing ansible roles with molecule
Inside ASP.NET MVC framework
Inside asp.net mvc framework
JMeter Database Performace Testing - Keytorc Approach
Integration Testing in Python
Apex Testing and Best Practices

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

PDF
DUTDIP - Don't Use This Dependency Injection Pattern
PPTX
Next Generation Language Go
PDF
Guice
PDF
sfdsdfsdfsdf
PDF
PPTX
The GO Language : From Beginners to Gophers
PDF
Golang dot-testing-lite
ODP
Ready to go
PDF
Go Lang Tutorial
KEY
Google Go Overview
PDF
I don't know what I'm Doing: A newbie guide for Golang for DevOps
PPTX
Introduction to GoLang
PPTX
From Complexity to Clarity: Crafting Seamless DI with Uber FX
PDF
Experiences Building InfluxDB in Go
PDF
Inroduction to golang
PDF
Learning Go Programming 1st Edition Vladimir Vivien all chapter instant download
KEY
Beauty and Power of Go
PDF
Services, dependencies, and you
PPTX
Scaling applications with go
PDF
From MEAN to the MERN Stack
DUTDIP - Don't Use This Dependency Injection Pattern
Next Generation Language Go
Guice
sfdsdfsdfsdf
The GO Language : From Beginners to Gophers
Golang dot-testing-lite
Ready to go
Go Lang Tutorial
Google Go Overview
I don't know what I'm Doing: A newbie guide for Golang for DevOps
Introduction to GoLang
From Complexity to Clarity: Crafting Seamless DI with Uber FX
Experiences Building InfluxDB in Go
Inroduction to golang
Learning Go Programming 1st Edition Vladimir Vivien all chapter instant download
Beauty and Power of Go
Services, dependencies, and you
Scaling applications with go
From MEAN to the MERN Stack
Ad

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
L1 - Introduction to python Backend.pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
medical staffing services at VALiNTRY
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
System and Network Administration Chapter 2
PDF
System and Network Administraation Chapter 3
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Odoo POS Development Services by CandidRoot Solutions
L1 - Introduction to python Backend.pptx
Digital Strategies for Manufacturing Companies
Wondershare Filmora 15 Crack With Activation Key [2025
PTS Company Brochure 2025 (1).pdf.......
Operating system designcfffgfgggggggvggggggggg
How to Choose the Right IT Partner for Your Business in Malaysia
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Softaken Excel to vCard Converter Software.pdf
medical staffing services at VALiNTRY
2025 Textile ERP Trends: SAP, Odoo & Oracle
ManageIQ - Sprint 268 Review - Slide Deck
System and Network Administration Chapter 2
System and Network Administraation Chapter 3
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Ad

DUTDIP - Don't Use This Dependency Injection

  • 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
  • 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
  • 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