SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
Scala Guice
Scala Guice - Motivation

  Google Guice with Scala is too verbose.

     val module = new AbstractModule() {

         override def configure() {
             bind(classOf[Service]).to(classOf[ServiceImpl])
             bind(classOf[BaseDao]).to(classOf[BaseDaoImpl])
         }
     }
Scala Guice - Motivation

  Google Guice with Scala is too verbose.

     val module = new AbstractModule() {

         override def configure() {
             bind(classOf[Service]).to(classOf[ServiceImpl])
             bind(classOf[BaseDao]).to(classOf[BaseDaoImpl])
         }
     }




  You write less code using Java.

     Module module = new AbstractModule() {
         @Override
         protected void configure() {
              bind(Service.class).to(ServiceImpl.class);
              bind(BaseDao.class).to(BaseDaoImpl.class);
         }
     };
Scala Guice - Motivation

  We can do it better if we use    scala.reflect.Manifest[T]


     val module = new ScalaModule() {

         override def configure() {
            bind[Service].to[ServiceImpl]
            bind[BaseDao].to[BaseDaoImpl]
         }
     }
Scala Guice - Motivation

  We can do it better if we use      scala.reflect.Manifest[T]


       val module = new ScalaModule() {

           override def configure() {
              bind[Service].to[ServiceImpl]
              bind[BaseDao].to[BaseDaoImpl]
           }
       }




   •   But we’ll have to mimic the whole Guice API...
Scala Guice - Motivation

  We can do it better if we use      scala.reflect.Manifest[T]


       val module = new ScalaModule() {

           override def configure() {
              bind[Service].to[ServiceImpl]
              bind[BaseDao].to[BaseDaoImpl]
           }
       }




   •   But we’ll have to mimic the whole Guice API...
   •   Only to remove classOf[]
Google Guice - internals
    Module module = new AbstractModule() {
        @Override
        protected void configure() {
             bind(Service.class).to(ServiceImpl.class);
             bind(BaseDao.class).to(BaseDaoImpl.class);
        }
    };



    protected <T> AnnotatedBindingBuilder<T> bind(Class<T>clazz) {
        return binder.bind(clazz);
    }
Google Guice - internals
    Module module = new AbstractModule() {
        @Override
        protected void configure() {
             bind(Service.class).to(ServiceImpl.class);
             bind(BaseDao.class).to(BaseDaoImpl.class);
        }
    };



    protected <T> AnnotatedBindingBuilder<T> bind(Class<T>clazz) {
        return binder.bind(clazz);
    }




   The binding starts as soon as method configure is called.

   The wiring is no dissociated from its definition.
Using Scala to express what you really want
I want to have my binding configuration independent of the binding process.

  val services : Configuration = config {
      bind[Service].to[ServiceImpl]
  }

  val daos : Configuration = config {
      bind[BaseDao].to[BaseDaoImpl]
  }
Using Scala to express what you really want
I want to have my binding configuration independent of the binding process.

  val services : Configuration = config {
      bind[Service].to[ServiceImpl]
  }

  val daos : Configuration = config {
      bind[BaseDao].to[BaseDaoImpl]
  }



I want to merge my configuration, without starting the binding.
  val mergedConfig = services ++ daos
Using Scala to express what you really want
I want to have my binding configuration independent of the binding process.

  val services : Configuration = config {
      bind[Service].to[ServiceImpl]
  }

  val daos : Configuration = config {
      bind[BaseDao].to[BaseDaoImpl]
  }



I want to merge my configuration, without starting the binding.
  val mergedConfig = services ++ daos



When I’m ready, I can pass my Configuration to a ScalaModule

  class ScalaModule(val configurations: Configuration*) extends AbstractModule {
      def configure() = configurations.foreach { c => c.bind(binder()) }
  }
Scala Guice - internals
 trait ConfigurationBuilder {
     def config(config: => Unit): Configuration = { ... }
     def bind[T](implicit manifT: Manifest[T]): ScalaAnnotatedBindingBuilder[T] = { ... }
 }

 object ConfigurationBuilder extends ConfigurationBuilder




Scala Guice Builders - mimic Guice API
• ScalaScopedBindingBuilder
• ScalaLinkedBindingBuilder
• ScalaAnnotatedBindingBuilder

 def to(impl: Class[_ <: T]): ScalaScopedBindingBuilder = {
     // delay call to builder
     linkedCommands += { (builder: LinkedBindingBuilder[T]) => builder.to(impl) }
     this
 }



 But real Guice call is recorded for later use
 Command pattern with Closures
Source code

 https://github.com/rcavalcanti/scala-guice


  • No production code
  • Not extensively tested
  • Not covering the whole Guice API

 Feedback and contributions are welcome!

Mais conteúdo relacionado

Mais procurados

"Inside The AngularJS Directive Compiler" by Tero Parviainen
"Inside The AngularJS Directive Compiler" by Tero Parviainen"Inside The AngularJS Directive Compiler" by Tero Parviainen
"Inside The AngularJS Directive Compiler" by Tero ParviainenFwdays
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 DreamLab
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)BoneyGawande
 
Demystifying Oak Search
Demystifying Oak SearchDemystifying Oak Search
Demystifying Oak SearchJustin Edelson
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxVisual Engineering
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgetsscottw
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideVisual Engineering
 
Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsVisual Engineering
 
Implement react pagination with react hooks and react paginate
Implement react pagination with react hooks and react paginateImplement react pagination with react hooks and react paginate
Implement react pagination with react hooks and react paginateKaty Slemon
 

Mais procurados (20)

"Inside The AngularJS Directive Compiler" by Tero Parviainen
"Inside The AngularJS Directive Compiler" by Tero Parviainen"Inside The AngularJS Directive Compiler" by Tero Parviainen
"Inside The AngularJS Directive Compiler" by Tero Parviainen
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
Firebase ng2 zurich
Firebase ng2 zurichFirebase ng2 zurich
Firebase ng2 zurich
 
Angular2 + rxjs
Angular2 + rxjsAngular2 + rxjs
Angular2 + rxjs
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
 
Demystifying Oak Search
Demystifying Oak SearchDemystifying Oak Search
Demystifying Oak Search
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
G pars
G parsG pars
G pars
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgets
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build tools
 
Implement react pagination with react hooks and react paginate
Implement react pagination with react hooks and react paginateImplement react pagination with react hooks and react paginate
Implement react pagination with react hooks and react paginate
 
Workshop 17: EmberJS parte II
Workshop 17: EmberJS parte IIWorkshop 17: EmberJS parte II
Workshop 17: EmberJS parte II
 

Destaque

Google Guice presentation at Montreal JUG - October 2010
Google Guice presentation at Montreal JUG - October 2010Google Guice presentation at Montreal JUG - October 2010
Google Guice presentation at Montreal JUG - October 2010Mathieu Carbou
 
Clean code via dependency injection + guice
Clean code via dependency injection + guiceClean code via dependency injection + guice
Clean code via dependency injection + guiceJordi Gerona
 
Ozma: Extending Scala with Oz concurrency
Ozma: Extending Scala with Oz concurrencyOzma: Extending Scala with Oz concurrency
Ozma: Extending Scala with Oz concurrencyBeScala
 
ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0Oscar Renalias
 
Guice - dependency injection framework
Guice - dependency injection frameworkGuice - dependency injection framework
Guice - dependency injection frameworkEvgeny Barabanov
 
Introduction to Google Guice
Introduction to Google GuiceIntroduction to Google Guice
Introduction to Google GuiceKnoldus Inc.
 
5-minute intro to property-based testing in Python with hypothesis
5-minute intro to property-based testing in Python with hypothesis5-minute intro to property-based testing in Python with hypothesis
5-minute intro to property-based testing in Python with hypothesisFranklin Chen
 

Destaque (9)

Google Guice presentation at Montreal JUG - October 2010
Google Guice presentation at Montreal JUG - October 2010Google Guice presentation at Montreal JUG - October 2010
Google Guice presentation at Montreal JUG - October 2010
 
Clean code via dependency injection + guice
Clean code via dependency injection + guiceClean code via dependency injection + guice
Clean code via dependency injection + guice
 
Ozma: Extending Scala with Oz concurrency
Ozma: Extending Scala with Oz concurrencyOzma: Extending Scala with Oz concurrency
Ozma: Extending Scala with Oz concurrency
 
ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0
 
Google Guice
Google GuiceGoogle Guice
Google Guice
 
Guice - dependency injection framework
Guice - dependency injection frameworkGuice - dependency injection framework
Guice - dependency injection framework
 
Eway google-guice presentation
Eway google-guice presentationEway google-guice presentation
Eway google-guice presentation
 
Introduction to Google Guice
Introduction to Google GuiceIntroduction to Google Guice
Introduction to Google Guice
 
5-minute intro to property-based testing in Python with hypothesis
5-minute intro to property-based testing in Python with hypothesis5-minute intro to property-based testing in Python with hypothesis
5-minute intro to property-based testing in Python with hypothesis
 

Semelhante a BeScala - Scala Guice

Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaDsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaUgo Matrangolo
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components EverywhereIlia Idakiev
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice PresentationDmitry Buzdin
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210Mahmoud Samir Fayed
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET AttributesPooja Gaikwad
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributessonia merchant
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularIlia Idakiev
 
ARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CIARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CICosmin Poieana
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributessonia merchant
 
The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196Mahmoud Samir Fayed
 
Custom AngularJS Directives
Custom AngularJS DirectivesCustom AngularJS Directives
Custom AngularJS Directivesyprodev
 
AngularJS Custom Directives
AngularJS Custom DirectivesAngularJS Custom Directives
AngularJS Custom Directivesyprodev
 
cloud foundry plugin doc for grails app
cloud foundry plugin doc for grails appcloud foundry plugin doc for grails app
cloud foundry plugin doc for grails appKanaka Durga
 

Semelhante a BeScala - Scala Guice (20)

Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaDsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components Everywhere
 
Solid angular
Solid angularSolid angular
Solid angular
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice Presentation
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With Angular
 
ARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CIARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CI
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Angular js
Angular jsAngular js
Angular js
 
Cloudformation101
Cloudformation101Cloudformation101
Cloudformation101
 
Spock's New Tricks
Spock's New TricksSpock's New Tricks
Spock's New Tricks
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributes
 
The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196
 
Custom AngularJS Directives
Custom AngularJS DirectivesCustom AngularJS Directives
Custom AngularJS Directives
 
AngularJS Custom Directives
AngularJS Custom DirectivesAngularJS Custom Directives
AngularJS Custom Directives
 
cloud foundry plugin doc for grails app
cloud foundry plugin doc for grails appcloud foundry plugin doc for grails app
cloud foundry plugin doc for grails app
 

Último

AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 

Último (20)

AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 

BeScala - Scala Guice

  • 2. Scala Guice - Motivation Google Guice with Scala is too verbose. val module = new AbstractModule() { override def configure() { bind(classOf[Service]).to(classOf[ServiceImpl]) bind(classOf[BaseDao]).to(classOf[BaseDaoImpl]) } }
  • 3. Scala Guice - Motivation Google Guice with Scala is too verbose. val module = new AbstractModule() { override def configure() { bind(classOf[Service]).to(classOf[ServiceImpl]) bind(classOf[BaseDao]).to(classOf[BaseDaoImpl]) } } You write less code using Java. Module module = new AbstractModule() { @Override protected void configure() { bind(Service.class).to(ServiceImpl.class); bind(BaseDao.class).to(BaseDaoImpl.class); } };
  • 4. Scala Guice - Motivation We can do it better if we use scala.reflect.Manifest[T] val module = new ScalaModule() { override def configure() { bind[Service].to[ServiceImpl] bind[BaseDao].to[BaseDaoImpl] } }
  • 5. Scala Guice - Motivation We can do it better if we use scala.reflect.Manifest[T] val module = new ScalaModule() { override def configure() { bind[Service].to[ServiceImpl] bind[BaseDao].to[BaseDaoImpl] } } • But we’ll have to mimic the whole Guice API...
  • 6. Scala Guice - Motivation We can do it better if we use scala.reflect.Manifest[T] val module = new ScalaModule() { override def configure() { bind[Service].to[ServiceImpl] bind[BaseDao].to[BaseDaoImpl] } } • But we’ll have to mimic the whole Guice API... • Only to remove classOf[]
  • 7. Google Guice - internals Module module = new AbstractModule() { @Override protected void configure() { bind(Service.class).to(ServiceImpl.class); bind(BaseDao.class).to(BaseDaoImpl.class); } }; protected <T> AnnotatedBindingBuilder<T> bind(Class<T>clazz) { return binder.bind(clazz); }
  • 8. Google Guice - internals Module module = new AbstractModule() { @Override protected void configure() { bind(Service.class).to(ServiceImpl.class); bind(BaseDao.class).to(BaseDaoImpl.class); } }; protected <T> AnnotatedBindingBuilder<T> bind(Class<T>clazz) { return binder.bind(clazz); } The binding starts as soon as method configure is called. The wiring is no dissociated from its definition.
  • 9. Using Scala to express what you really want I want to have my binding configuration independent of the binding process. val services : Configuration = config { bind[Service].to[ServiceImpl] } val daos : Configuration = config { bind[BaseDao].to[BaseDaoImpl] }
  • 10. Using Scala to express what you really want I want to have my binding configuration independent of the binding process. val services : Configuration = config { bind[Service].to[ServiceImpl] } val daos : Configuration = config { bind[BaseDao].to[BaseDaoImpl] } I want to merge my configuration, without starting the binding. val mergedConfig = services ++ daos
  • 11. Using Scala to express what you really want I want to have my binding configuration independent of the binding process. val services : Configuration = config { bind[Service].to[ServiceImpl] } val daos : Configuration = config { bind[BaseDao].to[BaseDaoImpl] } I want to merge my configuration, without starting the binding. val mergedConfig = services ++ daos When I’m ready, I can pass my Configuration to a ScalaModule class ScalaModule(val configurations: Configuration*) extends AbstractModule { def configure() = configurations.foreach { c => c.bind(binder()) } }
  • 12. Scala Guice - internals trait ConfigurationBuilder { def config(config: => Unit): Configuration = { ... } def bind[T](implicit manifT: Manifest[T]): ScalaAnnotatedBindingBuilder[T] = { ... } } object ConfigurationBuilder extends ConfigurationBuilder Scala Guice Builders - mimic Guice API • ScalaScopedBindingBuilder • ScalaLinkedBindingBuilder • ScalaAnnotatedBindingBuilder def to(impl: Class[_ <: T]): ScalaScopedBindingBuilder = { // delay call to builder linkedCommands += { (builder: LinkedBindingBuilder[T]) => builder.to(impl) } this } But real Guice call is recorded for later use Command pattern with Closures
  • 13. Source code https://github.com/rcavalcanti/scala-guice • No production code • Not extensively tested • Not covering the whole Guice API Feedback and contributions are welcome!

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n