Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add README-s

  • Loading branch information...
commit 3dabbee147708590a97a8df3c3829478214a3c03 1 parent 5ffb284
@pk11 pk11 authored
View
1  README.md
@@ -1,5 +1,6 @@
# Play Plugins
+plugins for the Play framework
## Licence
View
59 guice/README.md
@@ -0,0 +1,59 @@
+# Guice Plugin
+
+This plugin provides support for [Guice](http://code.google.com/p/google-guice/)
+
+# Features
+
+* Allows static field injection to a preconfigured package (controllers by default) ie
+```java
+public class Application extends Controller {
+
+ @Inject static Service s;
+
+ public static Result index() {
+ return ok(index.render(s.demonstrate()));
+ }
+
+}
+```
+* Dependency modules are configurable (by default it's ```module.Dependencies```)
+
+* Allows direct access to the factory method ie
+```java
+play.Play.application().plugin(InjectPlugin.class).getInstance(MyServiceInterface.class)```
+
+# How to install
+
+* add
+```"com.typesafe" % "play-plugins-guice" % "2.0-RC3"``` to your dependencies
+
+* create a file called ```play.plugins``` in your ```app/conf``` directory
+
+* add ```1500:com.typesafe.plugin.inject.GuicePlugin```
+
+* that' is
+
+# Testing
+
+* testing can be achieved two ways:
+
+** either making the injected dependencies anything but private
+
+** injected dependencies can be private in which case a new constructor could be added to controllers which could be used to inject the mocked dependencies
+
+I would recommend the former solution
+
+# Sample
+
+for a whole example, please see the bundled sample app
+
+
+## Licence
+
+This software is licensed under the Apache 2 license, quoted below.
+
+Copyright 2012 Typesafe (http://www.typesafe.com).
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
+
+Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
View
9 guice/sample/app/controllers/Application.java
@@ -12,15 +12,8 @@
@Inject static Service s;
- // used for testing, not used by Play
- //public Application(MyService s){
- // this.s = s;
- //}
-
public static Result index() {
- Logger.warn("CRAAAAP");
- Logger.warn(s.toString());
return ok(index.render(s.demonstrate()));
}
-}
+}
View
11 guice/src/main/java/com/typesafe/plugin/inject/GuicePlugin.java
@@ -62,18 +62,11 @@ public void onStart() {
* creates instance for default constructor
*/
private Object createInstane(Class<Object> clazz) throws java.lang.IllegalArgumentException {
- Constructor constructor = null;
- for(Constructor<?> c : clazz.getConstructors()) {
- if(c.getParameterTypes().length == 0) {
- constructor = c;
- break;
- }
- }
try {
- return constructor.newInstance();
+ return clazz.newInstance();
} catch (Exception ex) {
ex.printStackTrace();
throw new java.lang.IllegalArgumentException();
}
}
-}
+}
View
60 inject/README.md
@@ -0,0 +1,60 @@
+# Guice Plugin
+
+This plugin provides support for manual dependency injection. Injection points are defined using ```@Provides``` and ```@Singleton``` annotations in a file called ```module.Dependencies```.
+These would be injected into a preconfigured package (controllers by default)
+
+# Features
+
+* Allows static field injection to a preconfigured package (controllers by default) ie
+```java
+public class Application extends Controller {
+
+ @Inject static Service s;
+
+ public static Result index() {
+ return ok(index.render(s.demonstrate()));
+ }
+
+}
+```
+* Dependency modules are configurable (by default it's ```module.Dependencies```)
+
+* Allows direct access to the factory method ie
+```java
+play.Play.application().plugin(InjectPlugin.class).getInstance(MyServiceInterface.class)```
+
+# How to install
+
+* add
+```"com.typesafe" % "play-plugins-guice" % "2.0-RC3"``` to your dependencies
+
+* create a file called ```play.plugins``` in your ```app/conf``` directory
+
+* add ```1500:com.typesafe.plugin.inject.GuicePlugin```
+
+* that' is
+
+# Testing
+
+* testing can be achieved two ways:
+
+** either making the injected dependencies anything but private
+
+** injected dependencies can be private in which case a new constructor could be added to controllers which could be used to inject the mocked dependencies
+
+I would recommend the former solution
+
+# Sample
+
+for a whole example, please see the bundled sample app
+
+
+## Licence
+
+This software is licensed under the Apache 2 license, quoted below.
+
+Copyright 2012 Typesafe (http://www.typesafe.com).
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
+
+Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
View
9 inject/sample/app/controllers/Application.java
@@ -10,15 +10,10 @@
public class Application extends Controller {
- @Inject private static MyService s;
-
- // used for testing, not used by Play
- //public Application(MyService s){
- // this.s = s;
- //}
+ @Inject static MyService s;
public static Result index() {
return ok(index.render(s.demonstrate()));
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.