Book Image

Learning Google Guice

By : Hussain Pithawala
Book Image

Learning Google Guice

By: Hussain Pithawala

Overview of this book

<p>Google Guice is an open source software framework for the Java platform released by Google under the Apache License. It provides support for dependency injection using annotations to configure Java objects.</p> <p>Learning Google Guice is a concise, hands-on book that covers the various areas of dependency injection using the features provided by the latest version of Google Guice. It focuses on core functionalities as well as the various extensions surrounding Guice that make it useful in other areas like web development, integration with frameworks for web development, and persistence.</p> <p>Learning Google Guice covers Guice extensions which avoid complex API usage. You will start by developing a trivial application and managing dependencies using Guice. As the book gradually progresses, you will continue adding complexity to the application while simultaneously learning how to use Guice features such as the Injector, Provider, Bindings, Scopes, and so on. Finally, you will retrofit the application for the Web, using Guice not only to manage dependencies, but also to solve configuration related problems.</p>
Table of Contents (17 chapters)
Learning Google Guice
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Guice 3 with JPA 2


The extension guice-persist provides various classes, which facilitate the injection of EntityManger in our data access layer classes.

PersistService

PersistService is an interface, exposing two APIs, start and stop. The implementations of these two APIs means preparing and destroying the EntityManagerFactory instance, using Persistence.createEntityManagerFactory() API.

UnitOfWork

UnitOfWork is an interface, exposing two APIs, begin() and end(). The implementations of these two APIs necessarily mean creating an EntityManager instance using the EntityManagerFactory created earlier. It serves an essential purpose, because it opens the session for read-only operations, and closes them accordingly.

JpaPersistService

It is the implementation of the two interfaces we discussed as well as the Provider for EntityManager. JpaPersistService takes a String and a Properties reference as an argument to its constructor. JpaPersistService prepares and destroys the EntityManager when called...