SlideShare a Scribd company logo
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Revisit Dependency
Injection in Scala
Naoki Takezoe
@takezoen
at Airframe Meetup #3
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
What’s Dependency Injection?
● Inversion of Control
● Externalize components dependency and make it configurable
● Encourage clean components design
● Components can be replaced (e.g. for testing)
● Good collaboration with Aspect Oriented Programming
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Dependency Injection in Java
Explicit configuration to Less configuration
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Dependency Injection in Scala
● Java based DI container
○ Google Guice
● Pure Scala approach
○ Implicit parameter
○ Cake Pattern
○ Reader Monad, etc
● Scala native DI library
○ MacWire
○ Airframe
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Google Guice
● Widely used in Scala because of Play Framework
● Easy to use and understand
● Lack of Scala specific functionality
Define binding in Module
Use @Inject annotation for DI
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Implicit parameter
● No external library is required
● Easy to use and understand
● All necessary components must be in the same scope
Take necessary components as implicit parameter
Define necessary implicit val or def in the execution scope
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Cake Pattern
● No external library is required
● Boilerplate
Combine by mix-in
Declare dependency as self-type annotation
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Reader Monad
● Carry components around as an environment
● Need to put all necessary components together into the environment
Run with environment
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
MacWire
● Generate instance creation code with constructor injection by macro
● Rich features (e.g. multi binding, tagged binding, intercepter, etc)
● No boilerplate
● All necessary components must be in the same scope
Create instance using wire[T] macro
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Airframe
● Constructor injection and In-trait injection
● Rich features (e.g. tagged binding, type alias binding, config binding, etc)
● Less configuration by automatic instance creation
● Life-cycle management
In-trait injection
Define binding on Design if you need to
override default binding
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Runtime DI vs Compile-time DI
● Runtime DI
○ Google Guice
○ Airframe
● Compile-time ID
○ Pure Scala approaches
○ MacWire
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
Runtime DI vs Compile-time DI
Runtime DI Compile-time DI
Binding error Runtime error Compilation error
Configuration Less configuration Boilerplate is necessary
Life-cycle management Yes No
Overhead Runtime Compile-time
External library Required Not required / Required
Scala specific features Yes / No Yes
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.
What approach is the best?
● Do you need auto-wiring?
● Which do you need? compile-time dependency check or dynamic-type
binding?
● Do you need object life-cycle management?
Thank You!
Danke!
Merci!
谢谢!
ありがとう!
Gracias!
Kiitos!
Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.

More Related Content

What's hot (20)

PDF
Making your app soar without a container manifest
LibbySchulze
 
PDF
The Power of GitOps with Flux & GitOps Toolkit
Weaveworks
 
PDF
Intro to Kubernetes & GitOps Workshop
Weaveworks
 
PDF
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Red Hat Developers
 
PDF
[WSO2Con EU 2018] Deploying Applications in K8S and Docker
WSO2
 
PDF
Security: The Value of SBOMs
Weaveworks
 
PDF
Beyond OpenStack | OpenStack in Real Life
Opsta
 
PDF
Cncf storage-final-filip
Juraj Hantak
 
PDF
Kubernetes-native or not? When should you ditch your traditional CI/CD server...
Red Hat Developers
 
PDF
GitOps with Gitkube
Tirumarai Selvan
 
PDF
E bpf and profilers
LibbySchulze
 
PPTX
Get started with Kubernetes on GKE
Zachary Russell
 
PPTX
Meetup 23 - 03 - Application Delivery on K8S with GitOps
Vietnam Open Infrastructure User Group
 
PDF
Top 10 Kubernetes Native Java Quarkus Features
jclingan
 
PDF
Implementing MySQL Database-as-a-Service using open source tools
All Things Open
 
PDF
GitOps is the best modern practice for CD with Kubernetes
Volodymyr Shynkar
 
PDF
Git ops: Git based application deployment patterns for Kubernetes
Shahidh K Muhammed
 
PDF
Secure GitOps pipelines for Kubernetes with Snyk & Weaveworks
Weaveworks
 
PDF
GitOps Toolkit (Cloud Native Nordics Tech Talk)
Weaveworks
 
PDF
Gitops Hands On
Brice Fernandes
 
Making your app soar without a container manifest
LibbySchulze
 
The Power of GitOps with Flux & GitOps Toolkit
Weaveworks
 
Intro to Kubernetes & GitOps Workshop
Weaveworks
 
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Red Hat Developers
 
[WSO2Con EU 2018] Deploying Applications in K8S and Docker
WSO2
 
Security: The Value of SBOMs
Weaveworks
 
Beyond OpenStack | OpenStack in Real Life
Opsta
 
Cncf storage-final-filip
Juraj Hantak
 
Kubernetes-native or not? When should you ditch your traditional CI/CD server...
Red Hat Developers
 
GitOps with Gitkube
Tirumarai Selvan
 
E bpf and profilers
LibbySchulze
 
Get started with Kubernetes on GKE
Zachary Russell
 
Meetup 23 - 03 - Application Delivery on K8S with GitOps
Vietnam Open Infrastructure User Group
 
Top 10 Kubernetes Native Java Quarkus Features
jclingan
 
Implementing MySQL Database-as-a-Service using open source tools
All Things Open
 
GitOps is the best modern practice for CD with Kubernetes
Volodymyr Shynkar
 
Git ops: Git based application deployment patterns for Kubernetes
Shahidh K Muhammed
 
Secure GitOps pipelines for Kubernetes with Snyk & Weaveworks
Weaveworks
 
GitOps Toolkit (Cloud Native Nordics Tech Talk)
Weaveworks
 
Gitops Hands On
Brice Fernandes
 

Similar to Revisit Dependency Injection in scala (20)

PDF
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Taro L. Saito
 
PPTX
Introduction to dependency injection in Scala (Play)
Knoldus Inc.
 
PPTX
Introduction To MacWire
Knoldus Inc.
 
PDF
Dependency Injection in iOS
Pablo Villar
 
PDF
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Taro L. Saito
 
PDF
Airframe Meetup #3: 2019 Updates & AirSpec
Taro L. Saito
 
PDF
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Ugo Matrangolo
 
PDF
Dependency injection in scala
Michal Bigos
 
PPTX
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Theo Jungeblut
 
PPTX
Dependency injection using Google guice
Aman Verma
 
PPTX
Dependency Inversion Principle
Shahriar Hyder
 
PPTX
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Theo Jungeblut
 
PPTX
I gotta dependency on dependency injection
mhenroid
 
PDF
Techlunch - Dependency Injection with Vaadin
Peter Lehto
 
PDF
Spring Day | Spring and Scala | Eberhard Wolff
JAX London
 
PDF
Dependency injection on Android
Pedro Vicente Gómez Sánchez
 
PDF
Scala in Model-Driven development for Apparel Cloud Platform
Tomoharu ASAMI
 
PPTX
Clean Code Part II - Dependency Injection at SoCal Code Camp
Theo Jungeblut
 
PPTX
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Theo Jungeblut
 
PDF
Effective Scala: Programming Patterns
Vasil Remeniuk
 
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Taro L. Saito
 
Introduction to dependency injection in Scala (Play)
Knoldus Inc.
 
Introduction To MacWire
Knoldus Inc.
 
Dependency Injection in iOS
Pablo Villar
 
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Taro L. Saito
 
Airframe Meetup #3: 2019 Updates & AirSpec
Taro L. Saito
 
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Ugo Matrangolo
 
Dependency injection in scala
Michal Bigos
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Theo Jungeblut
 
Dependency injection using Google guice
Aman Verma
 
Dependency Inversion Principle
Shahriar Hyder
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Theo Jungeblut
 
I gotta dependency on dependency injection
mhenroid
 
Techlunch - Dependency Injection with Vaadin
Peter Lehto
 
Spring Day | Spring and Scala | Eberhard Wolff
JAX London
 
Dependency injection on Android
Pedro Vicente Gómez Sánchez
 
Scala in Model-Driven development for Apparel Cloud Platform
Tomoharu ASAMI
 
Clean Code Part II - Dependency Injection at SoCal Code Camp
Theo Jungeblut
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Theo Jungeblut
 
Effective Scala: Programming Patterns
Vasil Remeniuk
 
Ad

More from takezoe (20)

PDF
Journey of Migrating Millions of Queries on The Cloud
takezoe
 
PDF
Testing Distributed Query Engine as a Service
takezoe
 
PDF
頑張りすぎないScala
takezoe
 
PDF
Non-Functional Programming in Scala
takezoe
 
PDF
Scala警察のすすめ
takezoe
 
PDF
Scala製機械学習サーバ「Apache PredictionIO」
takezoe
 
PDF
The best of AltJava is Xtend
takezoe
 
PDF
Scala Warrior and type-safe front-end development with Scala.js
takezoe
 
PDF
Tracing Microservices with Zipkin
takezoe
 
PDF
Type-safe front-end development with Scala
takezoe
 
PDF
Scala Frameworks for Web Application 2016
takezoe
 
PDF
Macro in Scala
takezoe
 
PDF
Java9 and Project Jigsaw
takezoe
 
PDF
Reactive database access with Slick3
takezoe
 
PDF
markedj: The best of markdown processor on JVM
takezoe
 
PDF
ネタじゃないScala.js
takezoe
 
PDF
Excel方眼紙を支えるJava技術 2015
takezoe
 
PDF
ビズリーチの新サービスをScalaで作ってみた 〜マイクロサービスの裏側 #jissenscala
takezoe
 
PDF
GitBucket: The perfect Github clone by Scala
takezoe
 
PDF
Play2実践tips集
takezoe
 
Journey of Migrating Millions of Queries on The Cloud
takezoe
 
Testing Distributed Query Engine as a Service
takezoe
 
頑張りすぎないScala
takezoe
 
Non-Functional Programming in Scala
takezoe
 
Scala警察のすすめ
takezoe
 
Scala製機械学習サーバ「Apache PredictionIO」
takezoe
 
The best of AltJava is Xtend
takezoe
 
Scala Warrior and type-safe front-end development with Scala.js
takezoe
 
Tracing Microservices with Zipkin
takezoe
 
Type-safe front-end development with Scala
takezoe
 
Scala Frameworks for Web Application 2016
takezoe
 
Macro in Scala
takezoe
 
Java9 and Project Jigsaw
takezoe
 
Reactive database access with Slick3
takezoe
 
markedj: The best of markdown processor on JVM
takezoe
 
ネタじゃないScala.js
takezoe
 
Excel方眼紙を支えるJava技術 2015
takezoe
 
ビズリーチの新サービスをScalaで作ってみた 〜マイクロサービスの裏側 #jissenscala
takezoe
 
GitBucket: The perfect Github clone by Scala
takezoe
 
Play2実践tips集
takezoe
 
Ad

Recently uploaded (20)

PDF
intro_to_cpp_namespace_robotics_corner.pdf
MohamedSaied877003
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Ready Layer One: Intro to the Model Context Protocol
mmckenna1
 
PDF
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
PDF
Why is partnering with a SaaS development company crucial for enterprise succ...
Nextbrain Technologies
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PDF
Is Framer the Future of AI Powered No-Code Development?
Isla Pandora
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
Best Web development company in india 2025
Greenusys
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PPTX
From spreadsheets and delays to real-time control
SatishKumar2651
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PPTX
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
intro_to_cpp_namespace_robotics_corner.pdf
MohamedSaied877003
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Ready Layer One: Intro to the Model Context Protocol
mmckenna1
 
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
Why is partnering with a SaaS development company crucial for enterprise succ...
Nextbrain Technologies
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
Is Framer the Future of AI Powered No-Code Development?
Isla Pandora
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Best Web development company in india 2025
Greenusys
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
From spreadsheets and delays to real-time control
SatishKumar2651
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 

Revisit Dependency Injection in scala

  • 1. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Revisit Dependency Injection in Scala Naoki Takezoe @takezoen at Airframe Meetup #3
  • 2. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. What’s Dependency Injection? ● Inversion of Control ● Externalize components dependency and make it configurable ● Encourage clean components design ● Components can be replaced (e.g. for testing) ● Good collaboration with Aspect Oriented Programming
  • 3. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Dependency Injection in Java Explicit configuration to Less configuration
  • 4. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Dependency Injection in Scala ● Java based DI container ○ Google Guice ● Pure Scala approach ○ Implicit parameter ○ Cake Pattern ○ Reader Monad, etc ● Scala native DI library ○ MacWire ○ Airframe
  • 5. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Google Guice ● Widely used in Scala because of Play Framework ● Easy to use and understand ● Lack of Scala specific functionality Define binding in Module Use @Inject annotation for DI
  • 6. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Implicit parameter ● No external library is required ● Easy to use and understand ● All necessary components must be in the same scope Take necessary components as implicit parameter Define necessary implicit val or def in the execution scope
  • 7. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Cake Pattern ● No external library is required ● Boilerplate Combine by mix-in Declare dependency as self-type annotation
  • 8. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Reader Monad ● Carry components around as an environment ● Need to put all necessary components together into the environment Run with environment
  • 9. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. MacWire ● Generate instance creation code with constructor injection by macro ● Rich features (e.g. multi binding, tagged binding, intercepter, etc) ● No boilerplate ● All necessary components must be in the same scope Create instance using wire[T] macro
  • 10. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Airframe ● Constructor injection and In-trait injection ● Rich features (e.g. tagged binding, type alias binding, config binding, etc) ● Less configuration by automatic instance creation ● Life-cycle management In-trait injection Define binding on Design if you need to override default binding
  • 11. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Runtime DI vs Compile-time DI ● Runtime DI ○ Google Guice ○ Airframe ● Compile-time ID ○ Pure Scala approaches ○ MacWire
  • 12. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. Runtime DI vs Compile-time DI Runtime DI Compile-time DI Binding error Runtime error Compilation error Configuration Less configuration Boilerplate is necessary Life-cycle management Yes No Overhead Runtime Compile-time External library Required Not required / Required Scala specific features Yes / No Yes
  • 13. Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved. What approach is the best? ● Do you need auto-wiring? ● Which do you need? compile-time dependency check or dynamic-type binding? ● Do you need object life-cycle management?
  • 14. Thank You! Danke! Merci! 谢谢! ありがとう! Gracias! Kiitos! Copyright 1995-2019 Arm Limited (or its affiliates). All rights reserved.