Google guice It’s easy  © Skelia  201 1
Agenda Pattern Dependency injection Why we need DI Google guice introduction Guice simple injection  Integration with Servlets  Integration with Guice Philosophy Instead of summary Q&A  © Skelia 2011
DI or Don't Call Me, I Will Call You   Dependency injection  ( DI ) in  object-oriented   computer programming  is a technique that indicates to a part of a program which other parts it can use, i.e. to supply an  external dependency  – a reference – to a  software component . In technical terms, it is a  design pattern  that separates behavior from  dependency resolution , thus decoupling highly dependent components. © Skelia 2011 Wikipedia:  http://en.wikipedia.org/wiki/Dependency_injection
DI or Don't Call Me, I Will Call You   Dependency injection  ( DI ) in  object-oriented   computer programming  is a technique that indicates to a part of a program which other parts it can use, i.e. to supply an  external dependency  – a reference – to a  software component . In technical terms, it is a  design pattern  that separates behavior from  dependency resolution , thus decoupling highly dependent components. © Skelia 2011 Wikipedia:  http://en.wikipedia.org/wiki/Dependency_injection
DI or Don't Call Me, I Will Call You   © Skelia 2011
DI or Don't Call Me, I Will Call You   © Skelia 2011 Wild programmer Spaghetti Architecture
Google Guice © Skelia 2011 Google-Guice Current version 3.0 Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 5 and above, brought to you by Google.
Google Guice © Skelia 2011
Google Guice (Module) © Skelia 2011 Module Types: Non-obvious AbstractModule ServletModule
Google Guice (Binding) © Skelia 2011 Binding types: Bind implementation bind(PaymentCashImpl.class) Bind implementation to interface   bind(Payment.class).to(PaymentCardImpl.class)  Bind multiple implementation to interface bind(Payment.class).annotatedWith(Cash.class).to(PaymentCashImpl.class) bind(Payment.class).annotatedWith(Names.named("Cash")).to(PaymentCashImpl.class)
Google Guice (Injection) © Skelia 2011 Injection types : Constructor Method  Field (not recommended) @Inject private @Card Payment payment; @ Named("PaymentType") @Inject private String text;
Google Guice (Provides) © Skelia 2011   public class PayModule extends AbstractModule{     protected void configure() {     }       @Provides     Payment providePayment(){         CashPayment pay = new CashPayment();         pay.setAmount(100);         return pay;     } @Provides  List<String> providesListOfString() { return new ArrayList<String>(); } @Inject public void setList(List<String> list)
Google Guice (Scope) © Skelia 2011
Google Guice (AOP) © Skelia 2011
Google Guice (Sample) © Skelia 2011
Google Guice (Servlet integration) © Skelia 2011
Google Guice (Sample) © Skelia 2011
Google Guice (Integration) © Skelia 2011 Mobile RoboGuice - Guice for Android. Other Languages Groovy-Guice - Groovy Ninject - .NET Snake Guice - Python Smartypants-IOC - Flex/AS3 Dawn - AS3
Google Guice (Integration) © Skelia 2011
Google Guice (philosophy) © Skelia 2011
Google Guice (philosophy) © Skelia 2011
Instead of Conclusion  © Skelia 2011
Thank you ! © Skelia 2011

Google Guice

  • 1.
    Google guice It’seasy © Skelia 201 1
  • 2.
    Agenda Pattern Dependencyinjection Why we need DI Google guice introduction Guice simple injection Integration with Servlets Integration with Guice Philosophy Instead of summary Q&A © Skelia 2011
  • 3.
    DI or Don'tCall Me, I Will Call You Dependency injection  ( DI ) in  object-oriented   computer programming  is a technique that indicates to a part of a program which other parts it can use, i.e. to supply an  external dependency  – a reference – to a  software component . In technical terms, it is a  design pattern  that separates behavior from  dependency resolution , thus decoupling highly dependent components. © Skelia 2011 Wikipedia: http://en.wikipedia.org/wiki/Dependency_injection
  • 4.
    DI or Don'tCall Me, I Will Call You Dependency injection  ( DI ) in  object-oriented   computer programming  is a technique that indicates to a part of a program which other parts it can use, i.e. to supply an  external dependency  – a reference – to a  software component . In technical terms, it is a  design pattern  that separates behavior from  dependency resolution , thus decoupling highly dependent components. © Skelia 2011 Wikipedia: http://en.wikipedia.org/wiki/Dependency_injection
  • 5.
    DI or Don'tCall Me, I Will Call You © Skelia 2011
  • 6.
    DI or Don'tCall Me, I Will Call You © Skelia 2011 Wild programmer Spaghetti Architecture
  • 7.
    Google Guice ©Skelia 2011 Google-Guice Current version 3.0 Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 5 and above, brought to you by Google.
  • 8.
    Google Guice ©Skelia 2011
  • 9.
    Google Guice (Module)© Skelia 2011 Module Types: Non-obvious AbstractModule ServletModule
  • 10.
    Google Guice (Binding)© Skelia 2011 Binding types: Bind implementation bind(PaymentCashImpl.class) Bind implementation to interface bind(Payment.class).to(PaymentCardImpl.class) Bind multiple implementation to interface bind(Payment.class).annotatedWith(Cash.class).to(PaymentCashImpl.class) bind(Payment.class).annotatedWith(Names.named(&quot;Cash&quot;)).to(PaymentCashImpl.class)
  • 11.
    Google Guice (Injection)© Skelia 2011 Injection types : Constructor Method Field (not recommended) @Inject private @Card Payment payment; @ Named(&quot;PaymentType&quot;) @Inject private String text;
  • 12.
    Google Guice (Provides)© Skelia 2011   public class PayModule extends AbstractModule{   protected void configure() {     }     @Provides     Payment providePayment(){         CashPayment pay = new CashPayment();         pay.setAmount(100);         return pay;     } @Provides List<String> providesListOfString() { return new ArrayList<String>(); } @Inject public void setList(List<String> list)
  • 13.
    Google Guice (Scope)© Skelia 2011
  • 14.
    Google Guice (AOP)© Skelia 2011
  • 15.
    Google Guice (Sample)© Skelia 2011
  • 16.
    Google Guice (Servletintegration) © Skelia 2011
  • 17.
    Google Guice (Sample)© Skelia 2011
  • 18.
    Google Guice (Integration)© Skelia 2011 Mobile RoboGuice - Guice for Android. Other Languages Groovy-Guice - Groovy Ninject - .NET Snake Guice - Python Smartypants-IOC - Flex/AS3 Dawn - AS3
  • 19.
  • 20.
  • 21.
  • 22.
    Instead of Conclusion © Skelia 2011
  • 23.
    Thank you !© Skelia 2011