{"id":926,"date":"2012-02-13T19:36:00","date_gmt":"2012-02-13T19:36:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/play-framework-google-guice.html"},"modified":"2012-10-21T23:02:17","modified_gmt":"2012-10-21T23:02:17","slug":"play-framework-google-guice","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html","title":{"rendered":"Play! Framework + Google Guice"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">In the project I\u2019m currently working, we started to use Google Guice. For those who don\u2019t know, <a href=\"http:\/\/code.google.com\/p\/google-guice\/\">Google Guice<\/a> is a dependency injection framework. The basic idea behind dependency injection is to provide a class it\u2019s dependencies, instead of making the dependent class responsible of instantiating the objects on which it depends.<\/p>\n<p>Play has a module for integrating Guice:<br \/>\n<a href=\"http:\/\/www.playframework.org\/modules\/guice-1.2\/home\">http:\/\/www.playframework.org\/modules\/guice-1.2\/home<\/a><\/p>\n<p>In addition to the module documentation, this post from <a href=\"http:\/\/www.twitter.com\/_felipera\">@_felipera<\/a> can help you get started.<br \/>\n<a href=\"http:\/\/geeks.aretotally.in\/dependency-injection-with-play-framework-and-google-guice\">http:\/\/geeks.aretotally.in\/dependency-injection-with-play-framework-and-google-guice<\/a><\/p>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">How to use the Guice module<\/span><\/strong><\/p>\n<p><strong>Add the dependency<\/strong><\/p>\n<pre class=\"brush: java;\">require:\r\n  - play\r\n  - play -&gt; guice 1.2\r\n<\/pre>\n<p><strong>Download the dependencies<\/strong><\/p>\n<pre class=\"brush: java;\">play deps\r\n<\/pre>\n<p><strong>Create a new class that will be injected in the controller<\/strong><br \/>\nservices.MyService<\/p>\n<pre class=\"brush: java;\">package services;\r\npublic interface MyService {\r\n   public void sayHello();\r\n}\r\n<\/pre>\n<p>services.MyServiceImpl<\/p>\n<pre class=\"brush: java;\">package services;\r\npublic class MyServiceImpl implements MyService {\r\n    public MyServiceImpl(){\r\n        play.Logger.info(\"constructor!\");\r\n    }\r\n\r\n    @Override\r\n    public void sayHello() {\r\n        play.Logger.info(\"hello\");\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Configure the injector<\/strong><\/p>\n<pre class=\"brush: java;\">package config;\r\npublic class GuiceConfig extends GuiceSupport {\r\n    @Override\r\n    protected Injector configure() {\r\n        return Guice.createInjector(new AbstractModule() {\r\n            @Override\r\n            protected void configure() {\r\n                bind(MyService.class).to(MyServiceImpl.class).in(Singleton.class);\r\n            }\r\n        });\r\n    }\r\n}\r\n<\/pre>\n<p>This will setup the class as a singleton. Each time a class has the dependency of MyService, the injector will inject the same instance of MyServiceImpl.<\/p>\n<p><strong>Inject the dependency using the @Inject annotation<\/strong><\/p>\n<pre class=\"brush: java;\">package controllers;\r\npublic class Application extends Controller {\r\n\r\n    @Inject\r\n    static MyService myService;\r\n\r\n    public static void index() {\r\n        myService.sayHello();\r\n        render();\r\n    }\r\n}\r\n<\/pre>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Testing<\/span><\/strong><br \/>\nMy next step was to create a test and here came the first problem<\/p>\n<pre class=\"brush: java;\">play test\r\n<\/pre>\n<p><a href=\"http:\/\/localhost:9000\/@tests\">http:\/\/localhost:9000\/@tests<\/a><br \/>\nCompilation error! The problem is that the module has a folder called \u2018test\u2019. This folder should have some unit or functional test, but instead it has three sample applications. The convention in play modules is to have these kind of applications in the \u2018samples-and-test\u2019 folder.<\/p>\n<p>I made a fork of the project to rename this folder:<br \/>\n<a href=\"https:\/\/github.com\/axelhzf\/play-guice-module\">https:\/\/github.com\/axelhzf\/play-guice-module<\/a><br \/>\nI also did a pull-request but I didn\u2019t get any response so far :<br \/>\n<a href=\"https:\/\/github.com\/pk11\/play-guice-module\/pull\/5\">https:\/\/github.com\/pk11\/play-guice-module\/pull\/5<\/a><br \/>\nRenaming the folder \u2018test\u2019 was enough to run this test:<\/p>\n<pre class=\"brush: java;\">@InjectSupport\r\npublic class InjectTest extends UnitTest {\r\n    @Inject\r\n    static MyService myService;\r\n\r\n    @Test\r\n    public void injectOk(){\r\n        assertNotNull(myService);\r\n    }\r\n}\r\n<\/pre>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Adding more dependencies<\/span><\/strong><br \/>\nBy default, Play automatically detects the @Inject annotation on classes than inherit from Controller, Job and Mail. If you want to inject dependencies on other classes you must use the @InjectSupport.<br \/>\nTypically our services are not as simple as MyService. It is common to have dependencies between services. Guice solves this problem analyzing the dependencies and instantiating the objects in the proper order.<br \/>\nservices.MyDependentService<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush: java;\">package services;\r\n\r\npublic interface MyDependentService {\r\n    public void sayHelloWorld();\r\n}\r\n<\/pre>\n<p>service.MyDependentServiceImpl<\/p>\n<pre class=\"brush: java;\">package services;\r\n\r\n@InjectSupport\r\npublic class MyDependentServiceImpl implements MyDependentService {\r\n    @Inject\r\n    static MyService myService;\r\n\r\n    public MyDependentServiceImpl(){\r\n        play.Logger.info(\"Init MyDependentServiceImpl\");\r\n    }\r\n\r\n    public void sayHelloWorld(){\r\n        myService.sayHello();\r\n        play.Logger.info(\"world\");\r\n    }\r\n}\r\n<\/pre>\n<p>InjectTest<\/p>\n<pre class=\"brush: java;\">@InjectSupport\r\npublic class InjectTest extends UnitTest {\r\n\r\n@Inject\r\nstatic MyDependentService myDependentService;\r\n\r\n@Test\r\npublic void injectOk(){\r\n    assertNotNull(myDependentService);\r\n    myDependentService.sayHelloWorld();\r\n}\r\n\r\n}\r\n<\/pre>\n<p>Binding in GuiceConfig<\/p>\n<pre class=\"brush: java;\">bind(MyDependentService.class).to(MyDependentServiceImpl.class).in(Singleton.class);\r\n<\/pre>\n<p>And this is the console output<\/p>\n<pre class=\"brush: java;\">20:34:39,090 INFO ~ Init MyServiceImpl\r\n20:34:39,095 INFO ~ Init MyDependentServiceImpl\r\n20:34:39,095 INFO ~ Application 'lazySingleton' is now started !\r\n20:34:39,136 INFO ~ hello\r\n20:34:39,136 INFO ~ world\r\n<\/pre>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Constructor injection<\/span><\/strong><br \/>\nOne of the things I don\u2019t like about the module is that the fields you are allowed to inject must be static. I would prefer to declare the dependencies as constructor parameters. This way, it would be more obvious that to create an instance of MyDependentServiceImpl you need a MyService instance. Moreover, when working on units test, it\u2019s easier to pass a mock objects as a parameter than to configure an injector.<br \/>\nIn the module documentation I didn\u2019t found any reference to how to do it. Nevertheless, I found an article explaining how to do this using a Provider:<br \/>\n<a href=\"http:\/\/ericlefevre.net\/wordpress\/2011\/05\/08\/play-framework-and-guice-use-providers-in-guice-modules\/\">http:\/\/ericlefevre.net\/wordpress\/2011\/05\/08\/play-framework-and-guice-use-providers-in-guice-modules\/<\/a><br \/>\nLater, I found a question on StackOverflow that gave me another clue:<br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/8435686\/does-injector-getinstance-always-call-a-constructor\">http:\/\/stackoverflow.com\/questions\/8435686\/does-injector-getinstance-always-call-a-constructor<\/a><br \/>\nIn the <em>Edit<\/em> he says that he forgot to put the @Inject annotation in the constructor. I tried to do the same thing and finally it worked:<\/p>\n<pre class=\"brush: java;\">public class MyDependentServiceImpl implements MyDependentService {\r\n\r\n    private final MyService myService;\r\n    @Inject\r\n\r\n    public MyDependentServiceImpl(MyService myService){\r\n        this.myService = myService;\r\n        play.Logger.info(\"Inicializando MyDependentServiceImpl\");\r\n    }\r\n\r\n    ...\r\n<\/pre>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Lazy Singletons<\/span><\/strong><br \/>\nIt still remains one last detail to have a perfect google guice configuration.<br \/>\nThe services are initialized when the application starts.<\/p>\n<pre class=\"brush: java;\">21:38:11,801 INFO ~ Inicializando MyServiceImpl\r\n21:38:11,805 INFO ~ Inicializando MyDependentServiceImpl\r\n21:38:11,805 INFO ~ Application 'lazySingleton' is now started !\r\n<\/pre>\n<p>When the application is in production mode this is the correct behavior. But in development mode I prefer that Singletons are intialized on demand. There may be services that take their time to start and I want the application startup to be as fast as possible.<\/p>\n<p>With Google Guice you can achieve this using Scopes:<br \/>\n<a href=\"http:\/\/code.google.com\/p\/google-guice\/wiki\/Scopes\">http:\/\/code.google.com\/p\/google-guice\/wiki\/Scopes<\/a><br \/>\nAll you have to do is to set the Stage parameter:<\/p>\n<pre class=\"brush: java;\">Stage stage = Play.mode.isDev() ? Stage.DEVELOPMENT : Stage.PRODUCTION;\r\nreturn Guice.createInjector(stage, new AbstractModule() {\u2026..\r\n<\/pre>\n<p>Rerunning the test<\/p>\n<pre class=\"brush: java;\">22:00:03,353 WARN ~ You're running Play! in DEV mode\r\n22:00:04,615 INFO ~ Connected to jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0\r\n22:00:04,811 INFO ~ Guice injector created: config.GuiceConfig\r\n22:00:04,819 INFO ~ Init MyServiceImpl\r\n22:00:04,824 INFO ~ Init MyDependentServiceImpl\r\n22:00:04,824 INFO ~ Application 'lazySingleton' is now started !\r\n<\/pre>\n<p>Ooops! The Singleton are initialized before application starts. Perhaps that\u2019s not the correct use for the stage variable. Let\u2019s try a test:<\/p>\n<pre class=\"brush: java;\">public class StageTest {\r\n\r\n    @Test\r\n    public void testDevelopment(){\r\n        Injector injector = createInjector(Stage.DEVELOPMENT);\r\n        System.out.println(\"development - before getInstance\");\r\n        MyService instance = injector.getInstance(MyService.class);\r\n        System.out.println(\"development - after getInstance\");\r\n    }\r\n\r\n    @Test\r\n    public void testProduction(){\r\n        Injector injector = createInjector(Stage.PRODUCTION);\r\n        System.out.println(\"production - before getInstance\");\r\n        MyService instance = injector.getInstance(MyService.class);\r\n        System.out.println(\"production - after getInstance\");\r\n    }\r\n\r\n    public Injector createInjector(Stage stage){\r\n        Injector injector = Guice.createInjector(stage, new AbstractModule(){\r\n            @Override\r\n            protected void configure() {\r\n                bind(MyService.class).to(MyServiceImpl.class);\r\n            }\r\n        });\r\n        return injector;\r\n    }\r\n}\r\n<\/pre>\n<p>And the result is:<\/p>\n<pre class=\"brush: java;\">INFO: development - before getInstance\r\nINFO: Inicializando MyServiceImpl\r\nINFO: development - after getInstance\r\n\r\nINFO: Inicializando MyServiceImpl\r\nINFO: production - before getInstance\r\nINFO: production - after getInstance\r\n<\/pre>\n<p>Just like it says on the documentation, in development mode Singletons are initialized lazily.<br \/>\nIf this works, when I tried using the play module why didn\u2019t it work?<\/p>\n<p>Reviewing the code:<br \/>\n<a href=\"https:\/\/github.com\/pk11\/play-guice-module\/blob\/master\/src\/play\/modules\/guice\/GuicePlugin.java\">https:\/\/github.com\/pk11\/play-guice-module\/blob\/master\/src\/play\/modules\/guice\/GuicePlugin.java<\/a><br \/>\n@OnApplicationStart the module finds all classes annotated with @InjectSupport and inject it\u2019s dependencies. To inject the dependencies the module calls the getBean() method. And here we find the problem: when calling getBean() the class is instantiated.<\/p>\n<p>I found a solution to this problem:<br \/>\n<a href=\"https:\/\/groups.google.com\/d\/msg\/google-guice\/405HVgnCzsQ\/fBUuueP6NfsJ\">https:\/\/groups.google.com\/d\/msg\/google-guice\/405HVgnCzsQ\/fBUuueP6NfsJ<\/a><br \/>\nThis is the code:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/wiregit\/wirecode\/blob\/master\/components\/common\/src\/main\/java\/org\/limewire\/inject\/LazySingleton.java\">@LazySingleton<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/wiregit\/wirecode\/blob\/master\/components\/common\/src\/main\/java\/org\/limewire\/inject\/MoreScopes.java\">MoreScopes<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/wiregit\/wirecode\/blob\/master\/components\/common\/src\/main\/java\/org\/limewire\/inject\/LazyBinder.java\">LazyBinder<\/a><\/li>\n<\/ul>\n<p>These classes create a proxy for each class annotated as @LazySingleton. When the object is injected the injector actually injects the proxy. The first time a method is invoke, the proxy will take care of initializing the class.<\/p>\n<p>Using these classes, the injector configuration looks like:<\/p>\n<pre class=\"brush: java;\">public class GuiceConfig extends GuiceSupport {\r\n    @Override\r\n    protected Injector configure() {\r\n        Stage stage = Play.mode.isDev() ? Stage.DEVELOPMENT : Stage.PRODUCTION;\r\n        return Guice.createInjector(stage, new AbstractModule() {\r\n            @Override\r\n            protected void configure() {\r\n                bindScope(LazySingleton.class, MoreScopes.LAZY_SINGLETON);\r\n                bindLazySingletonOnDev(MyService.class, MyServiceImpl.class);\r\n                bindLazySingletonOnDev(MyDependentService.class, MyDependentServiceImpl.class);\r\n            }\r\n\r\n            protected &amp;lt;T&amp;gt; void bindLazySingletonOnDev(Class&amp;lt;T&amp;gt; expected, Class&amp;lt;? extends T&amp;gt; implClass){\r\n                if(Play.mode.isDev()){\r\n                    bind(implClass).in(MoreScopes.LAZY_SINGLETON);\r\n                    Provider&amp;lt;T&amp;gt; provider = LazyBinder.newLazyProvider(expected, implClass);\r\n                    bind(expected).toProvider(provider);\r\n                }else{\r\n                    bind(expected).to(implClass).in(Scopes.SINGLETON);\r\n                }\r\n            }\r\n        });\r\n    }\r\n}\r\n<\/pre>\n<p>I will add this classes to the fork in order to have a complete module that can be reused across projects.<\/p>\n<p><strong><span class=\"Apple-style-span\" style=\"font-size: large\">Conclusion<\/span><\/strong><br \/>\nIn the last few years Dependency Injection has has evolved from being an obscure and little understood term, to become part of every programmer\u2019s toolchest. In this article we saw how easy is to integrate Guice, a very handy library from Google, into a play framework application. Moreover, we also covered how to customize it\u2019s behaviour for a better development experience.<\/p>\n<p>Article original published at <a href=\"http:\/\/axelhzf.tumblr.com\/post\/16930248351\/play-framework-google-guice\" target=\"_blank\" title=\"http:\/\/axelhzf.tumblr.com\/\">http:\/\/axelhzf.tumblr.com<\/a>.<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/playlatam.wordpress.com\/2012\/02\/06\/playframework-google-guice\/\">Playframework + Google Guice<\/a>&nbsp;from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a><span class=\"Apple-style-span\" style=\"font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif\"><span class=\"Apple-style-span\" style=\"font-size: 14px;line-height: 18px\"><strong>&nbsp;<\/strong><\/span><\/span>Sebastian Scarano at the&nbsp;<a href=\"http:\/\/playlatam.wordpress.com\/\">Having fun with Play framework!<\/a>&nbsp;blog. <\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the project I\u2019m currently working, we started to use Google Guice. For those who don\u2019t know, Google Guice is a dependency injection framework. The basic idea behind dependency injection is to provide a class it\u2019s dependencies, instead of making the dependent class responsible of instantiating the objects on which it depends. Play has a &hellip;<\/p>\n","protected":false},"author":127,"featured_media":215,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[177],"class_list":["post-926","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-play-framework"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Play! Framework + Google Guice - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In the project I\u2019m currently working, we started to use Google Guice. For those who don\u2019t know, Google Guice is a dependency injection framework. The\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Play! Framework + Google Guice - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In the project I\u2019m currently working, we started to use Google Guice. For those who don\u2019t know, Google Guice is a dependency injection framework. The\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-02-13T19:36:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T23:02:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/play-framework-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sebastian Scarano\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Scarano\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html\"},\"author\":{\"name\":\"Sebastian Scarano\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/5739eadf2d1e11d81a1c1f52d3bb1ff1\"},\"headline\":\"Play! Framework + Google Guice\",\"datePublished\":\"2012-02-13T19:36:00+00:00\",\"dateModified\":\"2012-10-21T23:02:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html\"},\"wordCount\":893,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/play-framework-logo.jpg\",\"keywords\":[\"Play Framework\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html\",\"name\":\"Play! Framework + Google Guice - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/play-framework-logo.jpg\",\"datePublished\":\"2012-02-13T19:36:00+00:00\",\"dateModified\":\"2012-10-21T23:02:17+00:00\",\"description\":\"In the project I\u2019m currently working, we started to use Google Guice. For those who don\u2019t know, Google Guice is a dependency injection framework. The\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/play-framework-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/play-framework-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/02\\\/play-framework-google-guice.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Play! Framework + Google Guice\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/5739eadf2d1e11d81a1c1f52d3bb1ff1\",\"name\":\"Sebastian Scarano\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/10fe262e0211d7b9b4e7ccf1bb4c963e794272ea9c184a37f1b317bc03160a97?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/10fe262e0211d7b9b4e7ccf1bb4c963e794272ea9c184a37f1b317bc03160a97?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/10fe262e0211d7b9b4e7ccf1bb4c963e794272ea9c184a37f1b317bc03160a97?s=96&d=mm&r=g\",\"caption\":\"Sebastian Scarano\"},\"sameAs\":[\"http:\\\/\\\/playlatam.wordpress.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Sebastian-Scarano\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Play! Framework + Google Guice - Java Code Geeks","description":"In the project I\u2019m currently working, we started to use Google Guice. For those who don\u2019t know, Google Guice is a dependency injection framework. The","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html","og_locale":"en_US","og_type":"article","og_title":"Play! Framework + Google Guice - Java Code Geeks","og_description":"In the project I\u2019m currently working, we started to use Google Guice. For those who don\u2019t know, Google Guice is a dependency injection framework. The","og_url":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-02-13T19:36:00+00:00","article_modified_time":"2012-10-21T23:02:17+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/play-framework-logo.jpg","type":"image\/jpeg"}],"author":"Sebastian Scarano","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Sebastian Scarano","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html"},"author":{"name":"Sebastian Scarano","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/5739eadf2d1e11d81a1c1f52d3bb1ff1"},"headline":"Play! Framework + Google Guice","datePublished":"2012-02-13T19:36:00+00:00","dateModified":"2012-10-21T23:02:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html"},"wordCount":893,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/play-framework-logo.jpg","keywords":["Play Framework"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html","url":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html","name":"Play! Framework + Google Guice - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/play-framework-logo.jpg","datePublished":"2012-02-13T19:36:00+00:00","dateModified":"2012-10-21T23:02:17+00:00","description":"In the project I\u2019m currently working, we started to use Google Guice. For those who don\u2019t know, Google Guice is a dependency injection framework. The","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/play-framework-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/play-framework-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/02\/play-framework-google-guice.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Play! Framework + Google Guice"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/5739eadf2d1e11d81a1c1f52d3bb1ff1","name":"Sebastian Scarano","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/10fe262e0211d7b9b4e7ccf1bb4c963e794272ea9c184a37f1b317bc03160a97?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/10fe262e0211d7b9b4e7ccf1bb4c963e794272ea9c184a37f1b317bc03160a97?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/10fe262e0211d7b9b4e7ccf1bb4c963e794272ea9c184a37f1b317bc03160a97?s=96&d=mm&r=g","caption":"Sebastian Scarano"},"sameAs":["http:\/\/playlatam.wordpress.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Sebastian-Scarano"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/127"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=926"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/926\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/215"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}