This repository has been archived by the owner on Feb 9, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[inject] adding new sample demonstrating the staticless manual inject…
…ion approach
- Loading branch information
Showing
21 changed files
with
264 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
@(message: String) | ||
|
||
@main("Welcome to Play 2.0") { | ||
|
||
@play20.welcome(message, style = "Java") | ||
|
||
} | ||
@message |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import play.*; | ||
import play.libs.*; | ||
|
||
import java.util.*; | ||
|
||
import service.MyService; | ||
import com.typesafe.plugin.inject.InjectPlugin; | ||
|
||
public class Global extends GlobalSettings { | ||
|
||
public void onStart(Application app) { | ||
Logger.warn("getting an instance from guice:"+ app.plugin(InjectPlugin.class).getInstance(MyService.class)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
inject/sample_without_static_field/app/controllers/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package controllers; | ||
|
||
import play.*; | ||
import play.mvc.*; | ||
|
||
import views.html.*; | ||
|
||
import javax.inject.*; | ||
import service.*; | ||
|
||
public class Application extends Controller { | ||
|
||
private MyService s; | ||
|
||
@Inject public Application( MyService s) { | ||
this.s=s; | ||
} | ||
|
||
public Result index() { | ||
return ok(index.render(s.demonstrate())); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
inject/sample_without_static_field/app/module/Dependencies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package module; | ||
|
||
import com.google.inject.Provides; | ||
import javax.inject.Singleton; | ||
import service.*; | ||
import play.Play; | ||
import com.typesafe.plugin.inject.InjectPlugin; | ||
|
||
public class Dependencies { | ||
|
||
public static InjectPlugin inject() { | ||
return Play.application().plugin(InjectPlugin.class); | ||
} | ||
|
||
public static controllers.Application application() { | ||
return inject().getInstance(controllers.Application.class); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public Something makeSomething() { | ||
return new Something() { | ||
public String noWhat() { | ||
return "yay"; | ||
} | ||
}; | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public MyService makeService(Something s) { | ||
return new MyService(s) { | ||
public String demonstrate() { return s.noWhat();} | ||
}; | ||
} | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
inject/sample_without_static_field/app/service/MyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package service; | ||
|
||
public abstract class MyService { | ||
|
||
protected Something s; | ||
|
||
public MyService(Something s) { | ||
this.s = s; | ||
} | ||
|
||
abstract public String demonstrate(); | ||
} |
7 changes: 7 additions & 0 deletions
7
inject/sample_without_static_field/app/service/Something.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package service; | ||
|
||
public interface Something { | ||
|
||
public String noWhat(); | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
inject/sample_without_static_field/app/views/index.scala.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@(message: String) | ||
|
||
@message | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# This is the main configuration file for the application. | ||
# ~~~~~ | ||
|
||
# Secret key | ||
# ~~~~~ | ||
# The secret key is used to secure cryptographics functions. | ||
# If you deploy your application to several instances be sure to use the same key! | ||
application.secret="cBlQ[B0FM]DiFD<KIq6I`1TM81lna:gCo2XFAwdXo2lUIH;c:eL=_=N]o@UoblHu" | ||
|
||
# The application languages | ||
# ~~~~~ | ||
application.langs="en" | ||
|
||
# Global object class | ||
# ~~~~~ | ||
# Define the Global object class for this application. | ||
# Default to Global in the root package. | ||
# global=Global | ||
|
||
# Database configuration | ||
# ~~~~~ | ||
# You can declare as many datasources as you want. | ||
# By convention, the default datasource is named `default` | ||
# | ||
# db.default.driver=org.h2.Driver | ||
# db.default.url="jdbc:h2:mem:play" | ||
# db.default.user=sa | ||
# db.default.password= | ||
# | ||
# You can expose this datasource via JNDI if needed (Useful for JPA) | ||
# db.default.jndiName=DefaultDS | ||
|
||
# Evolutions | ||
# ~~~~~ | ||
# You can disable evolutions if needed | ||
# evolutionplugin=disabled | ||
|
||
# Ebean configuration | ||
# ~~~~~ | ||
# You can declare as many Ebean servers as you want. | ||
# By convention, the default server is named `default` | ||
# | ||
# ebean.default="models.*" | ||
|
||
# Logger | ||
# ~~~~~ | ||
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory . | ||
|
||
# Root logger: | ||
logger.root=ERROR | ||
|
||
# Logger used by the framework: | ||
logger.play=INFO | ||
|
||
# Logger provided to your application: | ||
logger.application=DEBUG | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1500:com.typesafe.plugin.inject.ManualInjectionPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Routes | ||
# This file defines all application routes (Higher priority routes first) | ||
# ~~~~ | ||
|
||
# Home page | ||
GET / module.Dependencies.application.index | ||
|
||
# Map static resources from the /public folder to the /assets URL path | ||
GET /assets/*file controllers.Assets.at(path="/public", file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sbt._ | ||
import Keys._ | ||
import PlayProject._ | ||
|
||
object ApplicationBuild extends Build { | ||
|
||
val appName = "j" | ||
val appVersion = "1.0-SNAPSHOT" | ||
|
||
val appDependencies = Seq( | ||
"com.typesafe" % "play-plugins-inject" % "2.0.2" | ||
|
||
) | ||
|
||
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings( | ||
// Add your own project settings here | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=0.11.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Comment to get more information during initialization | ||
logLevel := Level.Warn | ||
|
||
// The Typesafe repository | ||
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | ||
|
||
// Use the Play sbt plugin for Play projects | ||
addSbtPlugin("play" % "sbt-plugin" % "2.0.1") |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
inject/sample_without_static_field/public/javascripts/jquery-1.7.1.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.