SlideShare a Scribd company logo
1 of 14
Download to read offline
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

GitOps for Helm Users by Scott Rigby
GitOps for Helm Users by Scott RigbyGitOps for Helm Users by Scott Rigby
GitOps for Helm Users by Scott RigbyWeaveworks
 
Making your app soar without a container manifest
Making your app soar without a container manifestMaking your app soar without a container manifest
Making your app soar without a container manifestLibbySchulze
 
The Power of GitOps with Flux & GitOps Toolkit
The Power of GitOps with Flux & GitOps ToolkitThe Power of GitOps with Flux & GitOps Toolkit
The Power of GitOps with Flux & GitOps ToolkitWeaveworks
 
Intro to Kubernetes & GitOps Workshop
Intro to Kubernetes & GitOps WorkshopIntro to Kubernetes & GitOps Workshop
Intro to Kubernetes & GitOps WorkshopWeaveworks
 
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech TalkQuarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech TalkRed Hat Developers
 
[WSO2Con EU 2018] Deploying Applications in K8S and Docker
[WSO2Con EU 2018] Deploying Applications in K8S and Docker[WSO2Con EU 2018] Deploying Applications in K8S and Docker
[WSO2Con EU 2018] Deploying Applications in K8S and DockerWSO2
 
Security: The Value of SBOMs
Security: The Value of SBOMsSecurity: The Value of SBOMs
Security: The Value of SBOMsWeaveworks
 
Beyond OpenStack | OpenStack in Real Life
Beyond OpenStack | OpenStack in Real LifeBeyond OpenStack | OpenStack in Real Life
Beyond OpenStack | OpenStack in Real LifeOpsta
 
Cncf storage-final-filip
Cncf storage-final-filipCncf storage-final-filip
Cncf storage-final-filipJuraj Hantak
 
Kubernetes-native or not? When should you ditch your traditional CI/CD server...
Kubernetes-native or not? When should you ditch your traditional CI/CD server...Kubernetes-native or not? When should you ditch your traditional CI/CD server...
Kubernetes-native or not? When should you ditch your traditional CI/CD server...Red Hat Developers
 
E bpf and profilers
E bpf and profilersE bpf and profilers
E bpf and profilersLibbySchulze
 
Get started with Kubernetes on GKE
Get started with Kubernetes on GKEGet started with Kubernetes on GKE
Get started with Kubernetes on GKEZachary Russell
 
Top 10 Kubernetes Native Java Quarkus Features
Top 10 Kubernetes Native Java Quarkus FeaturesTop 10 Kubernetes Native Java Quarkus Features
Top 10 Kubernetes Native Java Quarkus Featuresjclingan
 
Implementing MySQL Database-as-a-Service using open source tools
Implementing MySQL Database-as-a-Service using open source toolsImplementing MySQL Database-as-a-Service using open source tools
Implementing MySQL Database-as-a-Service using open source toolsAll Things Open
 
GitOps is the best modern practice for CD with Kubernetes
GitOps is the best modern practice for CD with KubernetesGitOps is the best modern practice for CD with Kubernetes
GitOps is the best modern practice for CD with KubernetesVolodymyr Shynkar
 
Git ops: Git based application deployment patterns for Kubernetes
Git ops: Git based application deployment patterns for KubernetesGit ops: Git based application deployment patterns for Kubernetes
Git ops: Git based application deployment patterns for KubernetesShahidh K Muhammed
 
Secure GitOps pipelines for Kubernetes with Snyk & Weaveworks
Secure GitOps pipelines for Kubernetes with Snyk & WeaveworksSecure GitOps pipelines for Kubernetes with Snyk & Weaveworks
Secure GitOps pipelines for Kubernetes with Snyk & WeaveworksWeaveworks
 
GitOps Toolkit (Cloud Native Nordics Tech Talk)
GitOps Toolkit (Cloud Native Nordics Tech Talk)GitOps Toolkit (Cloud Native Nordics Tech Talk)
GitOps Toolkit (Cloud Native Nordics Tech Talk)Weaveworks
 

What's hot (20)

GitOps for Helm Users by Scott Rigby
GitOps for Helm Users by Scott RigbyGitOps for Helm Users by Scott Rigby
GitOps for Helm Users by Scott Rigby
 
Making your app soar without a container manifest
Making your app soar without a container manifestMaking your app soar without a container manifest
Making your app soar without a container manifest
 
The Power of GitOps with Flux & GitOps Toolkit
The Power of GitOps with Flux & GitOps ToolkitThe Power of GitOps with Flux & GitOps Toolkit
The Power of GitOps with Flux & GitOps Toolkit
 
Intro to Kubernetes & GitOps Workshop
Intro to Kubernetes & GitOps WorkshopIntro to Kubernetes & GitOps Workshop
Intro to Kubernetes & GitOps Workshop
 
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech TalkQuarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
 
[WSO2Con EU 2018] Deploying Applications in K8S and Docker
[WSO2Con EU 2018] Deploying Applications in K8S and Docker[WSO2Con EU 2018] Deploying Applications in K8S and Docker
[WSO2Con EU 2018] Deploying Applications in K8S and Docker
 
Security: The Value of SBOMs
Security: The Value of SBOMsSecurity: The Value of SBOMs
Security: The Value of SBOMs
 
Beyond OpenStack | OpenStack in Real Life
Beyond OpenStack | OpenStack in Real LifeBeyond OpenStack | OpenStack in Real Life
Beyond OpenStack | OpenStack in Real Life
 
Cncf storage-final-filip
Cncf storage-final-filipCncf storage-final-filip
Cncf storage-final-filip
 
Kubernetes-native or not? When should you ditch your traditional CI/CD server...
Kubernetes-native or not? When should you ditch your traditional CI/CD server...Kubernetes-native or not? When should you ditch your traditional CI/CD server...
Kubernetes-native or not? When should you ditch your traditional CI/CD server...
 
GitOps with Gitkube
GitOps with GitkubeGitOps with Gitkube
GitOps with Gitkube
 
E bpf and profilers
E bpf and profilersE bpf and profilers
E bpf and profilers
 
Get started with Kubernetes on GKE
Get started with Kubernetes on GKEGet started with Kubernetes on GKE
Get started with Kubernetes on GKE
 
Meetup 23 - 03 - Application Delivery on K8S with GitOps
Meetup 23 - 03 - Application Delivery on K8S with GitOpsMeetup 23 - 03 - Application Delivery on K8S with GitOps
Meetup 23 - 03 - Application Delivery on K8S with GitOps
 
Top 10 Kubernetes Native Java Quarkus Features
Top 10 Kubernetes Native Java Quarkus FeaturesTop 10 Kubernetes Native Java Quarkus Features
Top 10 Kubernetes Native Java Quarkus Features
 
Implementing MySQL Database-as-a-Service using open source tools
Implementing MySQL Database-as-a-Service using open source toolsImplementing MySQL Database-as-a-Service using open source tools
Implementing MySQL Database-as-a-Service using open source tools
 
GitOps is the best modern practice for CD with Kubernetes
GitOps is the best modern practice for CD with KubernetesGitOps is the best modern practice for CD with Kubernetes
GitOps is the best modern practice for CD with Kubernetes
 
Git ops: Git based application deployment patterns for Kubernetes
Git ops: Git based application deployment patterns for KubernetesGit ops: Git based application deployment patterns for Kubernetes
Git ops: Git based application deployment patterns for Kubernetes
 
Secure GitOps pipelines for Kubernetes with Snyk & Weaveworks
Secure GitOps pipelines for Kubernetes with Snyk & WeaveworksSecure GitOps pipelines for Kubernetes with Snyk & Weaveworks
Secure GitOps pipelines for Kubernetes with Snyk & Weaveworks
 
GitOps Toolkit (Cloud Native Nordics Tech Talk)
GitOps Toolkit (Cloud Native Nordics Tech Talk)GitOps Toolkit (Cloud Native Nordics Tech Talk)
GitOps Toolkit (Cloud Native Nordics Tech Talk)
 

Similar to Revisit Dependency Injection in Scala

Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Taro L. Saito
 
Airframe Meetup #3: 2019 Updates & AirSpec
Airframe Meetup #3: 2019 Updates & AirSpecAirframe Meetup #3: 2019 Updates & AirSpec
Airframe Meetup #3: 2019 Updates & AirSpecTaro L. Saito
 
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataHow To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataTaro L. Saito
 
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17Muga Nishizawa
 
Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...
Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...
Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...Cloud Native Day Tel Aviv
 
Cisco connect montreal 2018 saalvare md-program-xr-v2
Cisco connect montreal 2018 saalvare md-program-xr-v2Cisco connect montreal 2018 saalvare md-program-xr-v2
Cisco connect montreal 2018 saalvare md-program-xr-v2Cisco Canada
 
20191119 Cloud Native Java : GraalVM
20191119 Cloud Native Java : GraalVM20191119 Cloud Native Java : GraalVM
20191119 Cloud Native Java : GraalVMTaewan Kim
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTrivadis
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterTim Ellison
 
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...Yasen Lilov
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Waysmalltown
 
Managing Machine Learning workflows on Treasure Data
Managing Machine Learning workflows on Treasure DataManaging Machine Learning workflows on Treasure Data
Managing Machine Learning workflows on Treasure DataAki Ariga
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of PrestoTaro L. Saito
 
Aerospike O&M Webinar.pptx
Aerospike O&M Webinar.pptxAerospike O&M Webinar.pptx
Aerospike O&M Webinar.pptxAerospike Inc
 
Artifactory Essentials Workshop on August 27, 2020 by JFrog
Artifactory Essentials Workshop on August 27, 2020 by JFrogArtifactory Essentials Workshop on August 27, 2020 by JFrog
Artifactory Essentials Workshop on August 27, 2020 by JFrogCloud Study Network
 
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Taro L. Saito
 
2 ivan ma-mysql複製的演進和應用-twn- v1
2 ivan ma-mysql複製的演進和應用-twn- v12 ivan ma-mysql複製的演進和應用-twn- v1
2 ivan ma-mysql複製的演進和應用-twn- v1Ivan Tu
 
Graal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian WimmerGraal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian WimmerThomas Wuerthinger
 
JDD2015: Towards the Fastest (J)VM on the Planet! - Jaroslav Tulach
JDD2015: Towards the Fastest (J)VM on the Planet! - Jaroslav TulachJDD2015: Towards the Fastest (J)VM on the Planet! - Jaroslav Tulach
JDD2015: Towards the Fastest (J)VM on the Planet! - Jaroslav TulachPROIDEA
 
MongoDB @ Fiverr: The Road to Atlas
MongoDB @ Fiverr: The Road to AtlasMongoDB @ Fiverr: The Road to Atlas
MongoDB @ Fiverr: The Road to AtlasMongoDB
 

Similar to Revisit Dependency Injection in Scala (20)

Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
 
Airframe Meetup #3: 2019 Updates & AirSpec
Airframe Meetup #3: 2019 Updates & AirSpecAirframe Meetup #3: 2019 Updates & AirSpec
Airframe Meetup #3: 2019 Updates & AirSpec
 
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataHow To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
 
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
Custom Script Execution Environment on TD Workflow @ TD Tech Talk 2018-10-17
 
Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...
Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...
Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...
 
Cisco connect montreal 2018 saalvare md-program-xr-v2
Cisco connect montreal 2018 saalvare md-program-xr-v2Cisco connect montreal 2018 saalvare md-program-xr-v2
Cisco connect montreal 2018 saalvare md-program-xr-v2
 
20191119 Cloud Native Java : GraalVM
20191119 Cloud Native Java : GraalVM20191119 Cloud Native Java : GraalVM
20191119 Cloud Native Java : GraalVM
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance Interoperability
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark faster
 
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
 
Managing Machine Learning workflows on Treasure Data
Managing Machine Learning workflows on Treasure DataManaging Machine Learning workflows on Treasure Data
Managing Machine Learning workflows on Treasure Data
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of Presto
 
Aerospike O&M Webinar.pptx
Aerospike O&M Webinar.pptxAerospike O&M Webinar.pptx
Aerospike O&M Webinar.pptx
 
Artifactory Essentials Workshop on August 27, 2020 by JFrog
Artifactory Essentials Workshop on August 27, 2020 by JFrogArtifactory Essentials Workshop on August 27, 2020 by JFrog
Artifactory Essentials Workshop on August 27, 2020 by JFrog
 
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
 
2 ivan ma-mysql複製的演進和應用-twn- v1
2 ivan ma-mysql複製的演進和應用-twn- v12 ivan ma-mysql複製的演進和應用-twn- v1
2 ivan ma-mysql複製的演進和應用-twn- v1
 
Graal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian WimmerGraal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian Wimmer
 
JDD2015: Towards the Fastest (J)VM on the Planet! - Jaroslav Tulach
JDD2015: Towards the Fastest (J)VM on the Planet! - Jaroslav TulachJDD2015: Towards the Fastest (J)VM on the Planet! - Jaroslav Tulach
JDD2015: Towards the Fastest (J)VM on the Planet! - Jaroslav Tulach
 
MongoDB @ Fiverr: The Road to Atlas
MongoDB @ Fiverr: The Road to AtlasMongoDB @ Fiverr: The Road to Atlas
MongoDB @ Fiverr: The Road to Atlas
 

More from takezoe

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

More from takezoe (20)

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

Recently uploaded

Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
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
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 

Recently uploaded (20)

Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
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
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 

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.