MyFaces und Google Guice

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    MyFaces und Google Guice - Presentation Transcript

    1. Google Guice und Apache MyFaces 1.2 Matthias Weßendorf | matzew@apache.org
    2. Matthias Weßendorf
      • Oracle Corp.
        • ADFv team (ADF Faces)
      • Apache Software Foundation
        • Apache MyFaces (Trinidad | Core)
        • Apache Shale
      • Autor
        • Java- & Eclipse-Magazin
        • Bücher zu Struts, J2ME&WebServices
      • Speaker
        • Oracle Open World
        • JavaOne
        • JAX, W-JAX
        • ApacheCon
    3. Agenda
      • Dependency Injection
      • Google Guice
      • DI mit JSF
      • Integration
        • JSF und Google Guice
      • Ausblick
    4. Dependency Injection - I
      • Entwurfsmuster
        • Delegiert Erzeugung von Objekten
          • Service myService = new DefaultServiceImpl();
      • Vermeidet unnötige Abhängigkeiten
        •  DefaultServiceImpl
      • Vereinfacht das Testen
        •  MockServiceImpl
    5. Dependency Injection - II
      • DI von Hand:
        • public class ClientComponent {
        • ...
        • public void setService(Service service) {
        • this.service = service;
        • }
        • public void doSomething() {
        • service.doSomething();
        • }
        • }
        • ...
        • ClientComponent comp = new ClientComponent();
        • comp.setService( new DefaultServiceImpl() );
    6. Dependency Injection - III
      • DI mit Framework (Spring):
      • <bean class=&quot; de.jax.DefaultServiceImpl &quot; id=&quot; serviceImpl &quot; />
      • <bean class=&quot;ClientComponent&quot; id=&quot;client&quot; p: service -ref=&quot; serviceImpl &quot;/>
        • oder via Annotations (2.5)
    7. Dependency Injection - IV
      • Java
        • Spring
        • Pico
        • JavaServer Faces
      • Ruby
        • Needle
        • Copland
      • .NET
        • Spring.NET
      • add your language...
    8. Google Guice - I
      • lightweight DI Container (Java >= 5)
      • Java statt XML
        • Module Klassen  Konfiguration
        • Annotations
      • @Inject == the new new ...
      • Lead „crazy“ Bob Lee (Google)
    9. Google Guice - II
      • public class ClientComponent
      • {
      • @com.google.inject.Inject
      • private Service service;
      • public void doSomething()
      • {
      • service .doSomething();
      • }
      • }
    10. Google Guice - III
      • public class Module extends com.google.inject.AbstractModule
      • {
      • @Override
      • protected void configure()
      • {
      • bind( Service.class ).to( DefaultServiceImpl.class );
      • }
      • }
    11. Google Guice - IV
      • ...
      • Injector injector = Guice.createInjector( new Module(), ... );
      • ClientComponent cc = injector.getInstance( ClientComponent.class );
      • cc .doSomething();
      • ...
      • Ab Java 6:
        • ServiceLoader<com.google.inject.Module> modules = ServiceLoader.load(com.google.inject.Module.class);
        • Injector injector = Guice.createInjector(modules);
    12. DI mit JSF - I
      • public class BackingBean
      • {
      • ...
      • private Service service ;
      • //get und set Methode...
      • ...
      • public String actionMethod()
      • {
      • ...
      • getService().doSomething();
      • ...
      • }
      • }
    13. DI mit JSF - II
      • ...
      • <managed-bean>
      • <managed-bean-name> serviceImpl </managed-bean-name>
      • <managed-bean-class>
      • de.jax.DefaultServiceImpl
      • </managed-bean-class>
      • <managed-bean-scope> none </managed-bean-scope>
      • </managed-bean>
      • ...
    14. DI mit JSF - III
      • ...
      • <managed-bean>
      • <managed-bean-name>backingBean</managed-bean-name>
      • <managed-bean-class>de.jax.BackingBean</managed-bean-class>
      • <managed-bean-scope>request</managed-bean-scope>
      • <managed-property>
      • <property-name> service </property-name>
      • <property-class> de.jax.Service </property-class>
      • <value> #{serviceImpl} </value>
      • </managed-property>
      • </managed-bean>
      • ...
    15. Guice und Apache MyFaces - I
      • GuiceResolver (j avax.el.ELResolver )
      • Seit Apache MyFaces 1.2.2
        • MyFaces feature...
      • Nicht automatisch verfügbar...
      • Eintragen in faces-config.xml
      • <application>
      • <el-resolver>
      • org.apache.myfaces.el.unified.resolver.GuiceResolver
      • </el-resolver>
      • </application>
      • und ServeltContextListener...
    16. Guice und Apache MyFaces - II
      • public class GuiceServletContextListener implements ServletContextListener
      • {
      • public void contextInitialized(ServletContextEvent event)
      • {
      • ServletContext ctx = event.getServletContext();
      • ServiceLoader<com.google.inject.Module> modules ...
      • Injector injector = Guice.createInjector( modules );
      • ctx.setAttribute( GuiceResolver .KEY, injector);
      • }
      • public void contextDestroyed(ServletContextEvent event)
      • {
      • ServletContext ctx = event.getServletContext();
      • ctx.removeAttribute(GuiceResolver.KEY);
      • }
      • }
    17. Guice und Apache MyFaces - III
      • public class BackingBean
      • {
      • @Inject
      • private Service service ;
      • ...
      • public String actionMethod()
      • {
      • ...
      • service .doSomething();
      • ...
      • }
      • }
    18. Ausblick I
      • JBoss Seam
        • Komponentenmodell für JSF und EJB3
      • JSR 299 WebBeans
        • Standard für DI... (Ideen von Guice)
        • „ Standard“ für JBoss Seam
      • The Spring Framework
        • Ab 2.5  Java für Konfiguration ebenfalls möglich
    19. Ausblick II
      • DI mit WebBeans
      • package de.jax;
      • import javax.webbeans.*;
      • @Component
      • @RequestScoped
      • @Named(&quot;bean&quot;)
      • public class Bean
      • {
      • ...
      • @In Service service;
      • ...
      • }
    20. Q&A
      • Fragen ?
        • Danke!
        • Blog:
        • http://matthiaswessendorf.wordpress.com
        • Email:
        • matzew AT apache DOT org

    + mwessendorfmwessendorf, 2 years ago

    custom

    1302 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1302
      • 1302 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories