O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dependency injection using Guice

For this recipe, we will explore how to integrate Google Guice with a Play application. We will use Guice for bean instantiation and injection using Play controllers and service classes.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:
        activator "~run"
    
  2. Declare the guice module as a project dependency in build.sbt:
        "com.google.inject" % "guice" % "3.0"
  3. Configure Guice by modifying the contents of the Global settings class:
     import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; import play.GlobalSettings; import services.*; public class Global extends GlobalSettings ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required