SlideShare a Scribd company logo
Sapphire Gimlets*  Robert Cooper ReachCall.com *no onions
Guice Dependency Injection Java Source configuration Convention over configuration Fast
Gin Guice for GWT apps 100% Client Side Based on Deferred Binding, so some limitations Fast
Guicevs Spring Spring Config Hell Promise of simplicity Ever expanding config files Lots of subprojects Becomes more brittle, in that it becomes harder to extract code for reuse.
Guicevs Spring Guice Java Source “configuration” Convention over configuration. Annotation based Opposite of Spring in defaults Prefer constructor injection Prefer new instances (“Prototype”) over Singletons Provider<T> interface encourages mixing scopes Type Safe – you got static typing, use it!
Guice 101 Basic Annotations @Inject @ImplementedBy/@ProvidedBy @[Scope] @Named
Guice 101 public class MyClass{     private final MyService service;     @Injectpublic MyClass(finalMyService service){this.service = service;}     public String sayHelloToUser(){	return this.service.hello();} }    @ImplementedBy(MyServiceImpl.class)public interface MyService{     public String hello();}
Guice 101 @Singleton public class MyServiceImpl implements MyService {     private final Provider<MySessionObject> sessionProvider;     public MyServiceImpl(final Provider<MySessionObject> sessionProvider){ this.sessionProvider = sessionProvider;     }     @Override     public String hello() {         return "Hello, "+sessionProvider.get().getName() +"!";     } }
Guice 101 import com.google.inject.servlet.SessionScoped; @SessionScoped public class MySessionObject {     private String name;     public String getName(){         return this.name;     }     public void setName(String name){ this.name = name;     } }
Guice 101 What have we done? MyClass gets a MyService injected. MyService is implemented by MyServiceImpl as a Singleton MyServiceImpl gets a Provider<MySessionObject> The hello() method fetches the Session scoped MySession object, and says Hello!
Guice 101 @ImplementedBy provides defaults for any interface (You don’t need to config these if the default is OK) Injection is type safe on constructors (Unit tests have obvious requirements) Scope annotations (@SessionScoped, @Singleton) provide defaults. Provider<T> hides the scope shift from the Singleton service in a single thread method.
Guice 101 Making it work on the web…
Guice 101 public class GuiceContextListener extends GuiceServletContextListener {     @Override     protected Injector getInjector() {         return Guice.createInjector(             new Module() {     public void configure(Binder binder) {                   // Oh Wait, we don’t need anything here!                 }             }          }, new ServletModule() {                 @Override                 protected void configureServlets() { this.serve(“/myPath/*”).with(MyServlet.class);                 }           }     } }
Guice 101 Warning! Overly complicated coming up!
Guice 101 @Singleton public class MyServlet extends HttpServlet{     private final Provider<MySessionObject> sessionProvider;     private final MyClassmyClass;     @Inject     public MyServlet(final Provider<MySessionObject> sessionProvider, MyClassmyClass){ this.sessionProvider = sessionProvider; this.myClass = myClass;     }     @Override     public void doGet(HttpServletRequestreq, HttpServletResponse res) throws IOException { this.sessionProvider.get().setName(req.getParameter("name")); res.getWriter().println(myClass.hello());     } }
Guice 101 So this is interesting. What happened there? The SessionScoped object was created, and set on the session. MyClass was created one off for injection into the servlet. Since it wasn’t a Provider<MyClass> it was implicitly @Singleton with the servlet But since the MyClass implementation used a provider, it ended up performing a singleton-session scoped op.
Guice 101 What else? Servlets, Filters, etc must always be @Singleton of course, this just makes sense. They can *still* get anything injected into them. You need to add your boostrapGuiceContextListener to your web.xml For Servlet < 3.0 you need to add a com.google.inject.servlet.GuiceFilter to /*
Guice 201 Why does this rock? (Hint GWT stuff…)  Can you say RemoteServiceServlet? No more calls to getThreadLocalX() for servlet context stuff. Just use Provider<T>
Guice 201: Warp The Warp-* projects provide a lot of utility ops for Guice: @Transactional scope Transaction per Request Some stuff not dissimilar to Spring WebFlow or Stripes.
Guice 201: More Config @Named lets you provide named values in your configuration. (You can also create custom annotations) You can also use @Provides for factory methods in your modules for simple providers @Provides  public Connection getConnection(@Named(“jdbc-url”) String jdbcUrl) { DriverManager.forName(whatever); DriverManager.getConnection(jdbcUrl); }
Guice 201: More Config binder.bind(String.class).annotatedWith(Names.named(“jdbc-url”)).toInstance(“jdbc:mysql://localhost/mydb”); Note: @Provides methods could do JNDI lookups, or get other stuff. (This is a stupid example!)
Of Junipers and Bathtubs Gin is Google Guice for GWT client side apps. Based on DeferrredBinding. Certain features lost: Binding .toInstance() on any module Anonymous Provider<T> can’t be done (@Provides is *kinda* OK) Scoping needs to be by hard class reference.
Of Junipers and Bathtubs That is.. in(Singleton.class) not .asEagerSingleton() or with @Singleton Gin seems both stupid and too smart. Binding a RemoteServiceAsync class works out of the box… Unless you want to do @Provides Gin created classes are new Class() not GWT.create(Class.class); -- except for RemoteServiceAsync, which is a special scope.
Gin 101 @GinModules(MyGinModule.class) public interface Injector extends Ginjector {     public static final Injector INSTANCE = GWT.create(Injector.class);     public MyStartupClassstartupClass(); } public class Module extends AbstractGinModule {     @Override     protected void configure() { this.bind(Resources.class)             .toProvider(ResourcesProvider.class)             .in(Singleton.class)     } } public static class ResourcesProvider implements Provider<Resources> { @Override  public Resources get() {             return GWT.create(Resources.class);      } }
Gin 101 Does this step on the toes of DeBi?  OK, maybe a little bit. Sure you could do a singleton Resources.INSTANCE but injection makes Unit testing without dropping into GWTTestCase more frequent. (Read: much, much faster) This reserves DeBi for what it is best for: local environment specific code.
Gin 201 What can’t you do with Gin? Remember your Injector.INSTANCE is compile-time: No “toInstance()” bindings… ever. No “toProvider(AnonymousProvider(){})” providers need to be public scoped static classes at the least. Gin treats RemoteServiceAsync specially. You can do a provider, but if you try @Provides methods in your GinModule classes, you will get a duplicate declaration error.
Gin 201 All this aside, stacked with DeBi, Gin can rock rough and stuff with its Afro Puffs. Replace your Startup call with a Sync method. Replace your Async classes with thing that talk to local storage. Automagically retry onFailure() methods on network errors while your uses if offline.
Way way more Warp-* is some great stuff: http://code.google.com/p/warp-persist/ http://code.google.com/p/google-sitebricks/ Guice with JAX-WShttps://jax-ws-commons.dev.java.net/guice/ (Strangely harder than JAX-RS)

More Related Content

What's hot

End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
Babacar NIANG
 
Advanced VCL: how to use restart
Advanced VCL: how to use restartAdvanced VCL: how to use restart
Advanced VCL: how to use restart
Fastly
 
Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015
Fastly
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
Fastly
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
Ankit Agarwal
 
利用Init connect做mysql clients stat 用户审计
 利用Init connect做mysql clients stat 用户审计 利用Init connect做mysql clients stat 用户审计
利用Init connect做mysql clients stat 用户审计
Dehua Yang
 
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech TalkHacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Red Hat Developers
 
Enterprise Java Puzzlers
Enterprise Java PuzzlersEnterprise Java Puzzlers
Enterprise Java Puzzlers
Pavel Grushetzky
 
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Mike Nakhimovich
 
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Vielseitiges In-Memory Computing mit Apache Ignite und KubernetesVielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
QAware GmbH
 
OSGi Puzzlers - Neil Bartlett & Peter Kriens
OSGi Puzzlers - Neil Bartlett & Peter KriensOSGi Puzzlers - Neil Bartlett & Peter Kriens
OSGi Puzzlers - Neil Bartlett & Peter Kriens
mfrancis
 
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
EPAM_Systems_Bulgaria
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​
Luciano Mammino
 
Hands on: Hystrix
Hands on: HystrixHands on: Hystrix
Hands on: Hystrix
Christina Rasimus
 
Altitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshopAltitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshop
Fastly
 
Martin Anderson - threads v actors
Martin Anderson - threads v actorsMartin Anderson - threads v actors
Martin Anderson - threads v actors
bloodredsun
 
IPC: AIDL is sexy, not a curse
IPC: AIDL is sexy, not a curseIPC: AIDL is sexy, not a curse
IPC: AIDL is sexy, not a curse
Yonatan Levin
 
Ipc: aidl sexy, not a curse
Ipc: aidl sexy, not a curseIpc: aidl sexy, not a curse
Ipc: aidl sexy, not a curseYonatan Levin
 
Serverless, The Middy Way - Workshop
Serverless, The Middy Way - WorkshopServerless, The Middy Way - Workshop
Serverless, The Middy Way - Workshop
Luciano Mammino
 
Unqlite
UnqliteUnqlite

What's hot (20)

End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
 
Advanced VCL: how to use restart
Advanced VCL: how to use restartAdvanced VCL: how to use restart
Advanced VCL: how to use restart
 
Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
 
利用Init connect做mysql clients stat 用户审计
 利用Init connect做mysql clients stat 用户审计 利用Init connect做mysql clients stat 用户审计
利用Init connect做mysql clients stat 用户审计
 
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech TalkHacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
 
Enterprise Java Puzzlers
Enterprise Java PuzzlersEnterprise Java Puzzlers
Enterprise Java Puzzlers
 
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
 
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Vielseitiges In-Memory Computing mit Apache Ignite und KubernetesVielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
 
OSGi Puzzlers - Neil Bartlett & Peter Kriens
OSGi Puzzlers - Neil Bartlett & Peter KriensOSGi Puzzlers - Neil Bartlett & Peter Kriens
OSGi Puzzlers - Neil Bartlett & Peter Kriens
 
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
Tech Talks_25.04.15_Session 3_Tibor Sulyan_Distributed coordination with zook...
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​
 
Hands on: Hystrix
Hands on: HystrixHands on: Hystrix
Hands on: Hystrix
 
Altitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshopAltitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshop
 
Martin Anderson - threads v actors
Martin Anderson - threads v actorsMartin Anderson - threads v actors
Martin Anderson - threads v actors
 
IPC: AIDL is sexy, not a curse
IPC: AIDL is sexy, not a curseIPC: AIDL is sexy, not a curse
IPC: AIDL is sexy, not a curse
 
Ipc: aidl sexy, not a curse
Ipc: aidl sexy, not a curseIpc: aidl sexy, not a curse
Ipc: aidl sexy, not a curse
 
Serverless, The Middy Way - Workshop
Serverless, The Middy Way - WorkshopServerless, The Middy Way - Workshop
Serverless, The Middy Way - Workshop
 
Unqlite
UnqliteUnqlite
Unqlite
 

Viewers also liked

18. truong cong dat presentation
18. truong cong dat presentation18. truong cong dat presentation
18. truong cong dat presentationBinhThang
 
Amazing
AmazingAmazing
Amazing
Sam Ignarski
 
Things You Dont See Everyday
Things You Dont See EverydayThings You Dont See Everyday
Things You Dont See Everyday
Sam Ignarski
 
Extreme Source Compatibility
Extreme Source CompatibilityExtreme Source Compatibility
Extreme Source Compatibility
Robert Cooper
 
Galicia Calidade
Galicia CalidadeGalicia Calidade
Galicia Calidade
guest027ad
 
8. nguyen van hai
8. nguyen van hai8. nguyen van hai
8. nguyen van haiBinhThang
 
Introducing FOB Network
Introducing FOB NetworkIntroducing FOB Network
Introducing FOB Network
Sam Ignarski
 
6. le tan phung
6. le tan phung6. le tan phung
6. le tan phungBinhThang
 

Viewers also liked (9)

18. truong cong dat presentation
18. truong cong dat presentation18. truong cong dat presentation
18. truong cong dat presentation
 
Amazing
AmazingAmazing
Amazing
 
Things You Dont See Everyday
Things You Dont See EverydayThings You Dont See Everyday
Things You Dont See Everyday
 
Extreme Source Compatibility
Extreme Source CompatibilityExtreme Source Compatibility
Extreme Source Compatibility
 
Galicia Calidade
Galicia CalidadeGalicia Calidade
Galicia Calidade
 
8. nguyen van hai
8. nguyen van hai8. nguyen van hai
8. nguyen van hai
 
Introducing FOB Network
Introducing FOB NetworkIntroducing FOB Network
Introducing FOB Network
 
6. le tan phung
6. le tan phung6. le tan phung
6. le tan phung
 
Stop Complaining
Stop ComplainingStop Complaining
Stop Complaining
 

Similar to Sapphire Gimlets

Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 BejugEnterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejugrobbiev
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice PresentationDmitry Buzdin
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalDroidcon Berlin
 
GWT MVP Case Study
GWT MVP Case StudyGWT MVP Case Study
GWT MVP Case Study
David Chandler
 
GWT Extreme!
GWT Extreme!GWT Extreme!
GWT Extreme!
cromwellian
 
Das kannste schon so machen
Das kannste schon so machenDas kannste schon so machen
Das kannste schon so machen
André Goliath
 
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverCassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
DataStax Academy
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
 
guice-servlet
guice-servletguice-servlet
guice-servlet
Masaaki Yonebayashi
 
Guice
GuiceGuice
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011telestax
 
SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8
Ben Abdallah Helmi
 
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten ZiegelerOSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
mfrancis
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
Yiguang Hu
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testabilitydrewz lin
 
Getting Started with Datatsax .Net Driver
Getting Started with Datatsax .Net DriverGetting Started with Datatsax .Net Driver
Getting Started with Datatsax .Net DriverDataStax Academy
 
06 response-headers
06 response-headers06 response-headers
06 response-headerssnopteck
 
Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02
rhemsolutions
 

Similar to Sapphire Gimlets (20)

Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 BejugEnterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice Presentation
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
 
GWT MVP Case Study
GWT MVP Case StudyGWT MVP Case Study
GWT MVP Case Study
 
Devoxx 2012 (v2)
Devoxx 2012 (v2)Devoxx 2012 (v2)
Devoxx 2012 (v2)
 
GWT Extreme!
GWT Extreme!GWT Extreme!
GWT Extreme!
 
Das kannste schon so machen
Das kannste schon so machenDas kannste schon so machen
Das kannste schon so machen
 
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverCassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
guice-servlet
guice-servletguice-servlet
guice-servlet
 
Guice
GuiceGuice
Guice
 
Guice
GuiceGuice
Guice
 
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
 
SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8
 
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten ZiegelerOSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
Getting Started with Datatsax .Net Driver
Getting Started with Datatsax .Net DriverGetting Started with Datatsax .Net Driver
Getting Started with Datatsax .Net Driver
 
06 response-headers
06 response-headers06 response-headers
06 response-headers
 
Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

Sapphire Gimlets

  • 1. Sapphire Gimlets* Robert Cooper ReachCall.com *no onions
  • 2. Guice Dependency Injection Java Source configuration Convention over configuration Fast
  • 3. Gin Guice for GWT apps 100% Client Side Based on Deferred Binding, so some limitations Fast
  • 4. Guicevs Spring Spring Config Hell Promise of simplicity Ever expanding config files Lots of subprojects Becomes more brittle, in that it becomes harder to extract code for reuse.
  • 5. Guicevs Spring Guice Java Source “configuration” Convention over configuration. Annotation based Opposite of Spring in defaults Prefer constructor injection Prefer new instances (“Prototype”) over Singletons Provider<T> interface encourages mixing scopes Type Safe – you got static typing, use it!
  • 6. Guice 101 Basic Annotations @Inject @ImplementedBy/@ProvidedBy @[Scope] @Named
  • 7. Guice 101 public class MyClass{ private final MyService service; @Injectpublic MyClass(finalMyService service){this.service = service;} public String sayHelloToUser(){ return this.service.hello();} } @ImplementedBy(MyServiceImpl.class)public interface MyService{ public String hello();}
  • 8. Guice 101 @Singleton public class MyServiceImpl implements MyService { private final Provider<MySessionObject> sessionProvider; public MyServiceImpl(final Provider<MySessionObject> sessionProvider){ this.sessionProvider = sessionProvider; } @Override public String hello() { return "Hello, "+sessionProvider.get().getName() +"!"; } }
  • 9. Guice 101 import com.google.inject.servlet.SessionScoped; @SessionScoped public class MySessionObject { private String name; public String getName(){ return this.name; } public void setName(String name){ this.name = name; } }
  • 10. Guice 101 What have we done? MyClass gets a MyService injected. MyService is implemented by MyServiceImpl as a Singleton MyServiceImpl gets a Provider<MySessionObject> The hello() method fetches the Session scoped MySession object, and says Hello!
  • 11. Guice 101 @ImplementedBy provides defaults for any interface (You don’t need to config these if the default is OK) Injection is type safe on constructors (Unit tests have obvious requirements) Scope annotations (@SessionScoped, @Singleton) provide defaults. Provider<T> hides the scope shift from the Singleton service in a single thread method.
  • 12. Guice 101 Making it work on the web…
  • 13. Guice 101 public class GuiceContextListener extends GuiceServletContextListener { @Override protected Injector getInjector() { return Guice.createInjector( new Module() { public void configure(Binder binder) { // Oh Wait, we don’t need anything here! } } }, new ServletModule() { @Override protected void configureServlets() { this.serve(“/myPath/*”).with(MyServlet.class); } } } }
  • 14. Guice 101 Warning! Overly complicated coming up!
  • 15. Guice 101 @Singleton public class MyServlet extends HttpServlet{ private final Provider<MySessionObject> sessionProvider; private final MyClassmyClass; @Inject public MyServlet(final Provider<MySessionObject> sessionProvider, MyClassmyClass){ this.sessionProvider = sessionProvider; this.myClass = myClass; } @Override public void doGet(HttpServletRequestreq, HttpServletResponse res) throws IOException { this.sessionProvider.get().setName(req.getParameter("name")); res.getWriter().println(myClass.hello()); } }
  • 16. Guice 101 So this is interesting. What happened there? The SessionScoped object was created, and set on the session. MyClass was created one off for injection into the servlet. Since it wasn’t a Provider<MyClass> it was implicitly @Singleton with the servlet But since the MyClass implementation used a provider, it ended up performing a singleton-session scoped op.
  • 17. Guice 101 What else? Servlets, Filters, etc must always be @Singleton of course, this just makes sense. They can *still* get anything injected into them. You need to add your boostrapGuiceContextListener to your web.xml For Servlet < 3.0 you need to add a com.google.inject.servlet.GuiceFilter to /*
  • 18. Guice 201 Why does this rock? (Hint GWT stuff…) Can you say RemoteServiceServlet? No more calls to getThreadLocalX() for servlet context stuff. Just use Provider<T>
  • 19. Guice 201: Warp The Warp-* projects provide a lot of utility ops for Guice: @Transactional scope Transaction per Request Some stuff not dissimilar to Spring WebFlow or Stripes.
  • 20. Guice 201: More Config @Named lets you provide named values in your configuration. (You can also create custom annotations) You can also use @Provides for factory methods in your modules for simple providers @Provides public Connection getConnection(@Named(“jdbc-url”) String jdbcUrl) { DriverManager.forName(whatever); DriverManager.getConnection(jdbcUrl); }
  • 21. Guice 201: More Config binder.bind(String.class).annotatedWith(Names.named(“jdbc-url”)).toInstance(“jdbc:mysql://localhost/mydb”); Note: @Provides methods could do JNDI lookups, or get other stuff. (This is a stupid example!)
  • 22. Of Junipers and Bathtubs Gin is Google Guice for GWT client side apps. Based on DeferrredBinding. Certain features lost: Binding .toInstance() on any module Anonymous Provider<T> can’t be done (@Provides is *kinda* OK) Scoping needs to be by hard class reference.
  • 23. Of Junipers and Bathtubs That is.. in(Singleton.class) not .asEagerSingleton() or with @Singleton Gin seems both stupid and too smart. Binding a RemoteServiceAsync class works out of the box… Unless you want to do @Provides Gin created classes are new Class() not GWT.create(Class.class); -- except for RemoteServiceAsync, which is a special scope.
  • 24. Gin 101 @GinModules(MyGinModule.class) public interface Injector extends Ginjector { public static final Injector INSTANCE = GWT.create(Injector.class); public MyStartupClassstartupClass(); } public class Module extends AbstractGinModule { @Override protected void configure() { this.bind(Resources.class) .toProvider(ResourcesProvider.class) .in(Singleton.class) } } public static class ResourcesProvider implements Provider<Resources> { @Override public Resources get() { return GWT.create(Resources.class); } }
  • 25. Gin 101 Does this step on the toes of DeBi? OK, maybe a little bit. Sure you could do a singleton Resources.INSTANCE but injection makes Unit testing without dropping into GWTTestCase more frequent. (Read: much, much faster) This reserves DeBi for what it is best for: local environment specific code.
  • 26. Gin 201 What can’t you do with Gin? Remember your Injector.INSTANCE is compile-time: No “toInstance()” bindings… ever. No “toProvider(AnonymousProvider(){})” providers need to be public scoped static classes at the least. Gin treats RemoteServiceAsync specially. You can do a provider, but if you try @Provides methods in your GinModule classes, you will get a duplicate declaration error.
  • 27. Gin 201 All this aside, stacked with DeBi, Gin can rock rough and stuff with its Afro Puffs. Replace your Startup call with a Sync method. Replace your Async classes with thing that talk to local storage. Automagically retry onFailure() methods on network errors while your uses if offline.
  • 28. Way way more Warp-* is some great stuff: http://code.google.com/p/warp-persist/ http://code.google.com/p/google-sitebricks/ Guice with JAX-WShttps://jax-ws-commons.dev.java.net/guice/ (Strangely harder than JAX-RS)