Guice

Page 1

Guice by Google

A lightweight DI framework Madalin Ilie 12.09.2012


Agenda

• Who? • IoC and DI • What? • Why? • How? • When? • Cons • References

2


Guice

WHO?

IN YOUR ZONE

3


Guice – Who?

•7+ years in Software Development •Java Discipline Lead @Endava •SoS Scrum Master in a financial project watching over 6 SCRUM teams

•Technical interviewer •Java SE, EE, Mobile & many frameworks IN YOUR ZONE

4


Guice – IoC & DI

The Hollywood principle

Don’t call us, we’ll call you! IN YOUR ZONE

5


Guice – IoC & DI

pom.xml of a simple project

IN YOUR ZONE

6


Guice – IoC & DI

IoC > DI pom.xml of a simple project

IN YOUR ZONE

7


Guice – IoC & DI

Others

EDP

pom.xml of a simple project

IoC DI

IN YOUR ZONE

8


Guice – IoC & DI

IN YOUR ZONE

9


Guice – IoC & DI

IN YOUR ZONE

10


Guice – What?

DI frameworks

IoC containers

IN YOUR ZONE

11


Guice – What?

•DI framework •Lightweight •Easy to use •Typesafe •Customizable •Java based – no XML •@Inject is the new new IN YOUR ZONE

12


Guice – Why?

• More upfront type checking -> less errors •Easier to write better code •Easier to write testable code •Easy to extend •More readable code •JSR330 compliant IN YOUR ZONE

13


Guice – How? – Key Concepts

Bindings

•You specify how dependencies are resolved

IN YOUR ZONE

14


Guice – How? – Key Concepts

Modules

•Defines a set of bindings

IN YOUR ZONE

15


Guice – How? – Key Concepts

Injectors

•Based on one or more modules

•Tracks the dependencies for each type and uses bindings to inject them

IN YOUR ZONE

16


Guice – How? – Key Concepts

Providers

•Lazy loading •Get multiple instances on the same injection point •Mix scopes •Instead of binding to T, we bind to Provider<T>

IN YOUR ZONE

17


Guice – How? – Key Concepts

Scopes

•@Singleton •Default aka Prototype •@SessionScoped •@RequestScoped •Custom IN YOUR ZONE

18


Guice – How? – Key Concepts

Extensions

•Servlet •Spring •Struts •Persist •JMX •JNDI •AOP IN YOUR ZONE

19


Guice – How? – Key Concepts

Guice Web

•No more web.xml config •Minimum configuration •Extend ServletModule for servlet and filter bindings

•Can be integrated with legacy appliactions IN YOUR ZONE

20


Guice vs …

IN YOUR ZONE

21


Guice – When?

Spring

IN YOUR ZONE

Guice

22


Guice

Q&A IN YOUR ZONE

23


The end

Madalin Ilie| Development Lead Madalin.ilie@endava.com Tel +40 752 175 185 |Skype en_milie

thank you

IN YOUR ZONE

24


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.