Here is an exemple. Let's define two controllers:
------
package controllers;
import play.mvc.*;
public class Controller1 extends Controller {
public Result index() {
return ok("INDEX 1");
}
}
-------
package controllers;
import play.mvc.*;
public class Controller2 extends Controller {
public Result index() {
return ok("INDEX 2");
}
}
------
Note that here the action methods are not static. So there is no way
for Play to invoke them.
We need to create instances of these controllers. Let's write a
controllers factory:
-----
package controllers;
public class Application {
public static Controller1 controller1() {
return new Controller1();
}
public static Controller2 controller2() {
return new Controller2();
}
}
----
Here we create a new controller instance for each request. We could
also apply the singleton pattern and keep a single instance for the
whole application.
.... Or retrieve the controller instance from Spring (with
dependencies injection already managed by Spring):
-----
package controllers;
public class Application {
static ApplicationContext ctx = initStuff(...);
public static Controller1 controller1() {
return ctx.get("controller1");
}
public static Controller2 controller2() {
return ctx.get("controller2");
}
}
----
How does the routing/reverse routing work? The same way:
GET /index1 controllers.Application.controller1.index()
GET /index2 controllers.Application.controller2.index()
And to reverse:
routes.Application.controller2.index()
Hope that give you some ideas for your plugin.
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.
--
Guillaume Bort
Just a tip: you can host your own maven repo on github.
If you create a repo named <username>.github.com its files will be available at http://<username>.github.com
Have a look at http:/github.com/mbknor to see how i publish my projects, for example gt-engine-play2
-morten
There's not going to ever be one way. My best guess is that neither Guice, Spring, or another DI framework will be included in the core distribution of Play. These are all perfect examples of the use-case for modules. Really play don't need a dependency injections framework, the need is mostly driven by the requirement of integrating Play with other APIs who use dependency injection. I think for your typical small play app dependency injection is overkill that just adds complexity and slows down development without bringing any practical benefits to the table.
The real question is what is better for your project Guice, Spring, something else, or nothing at all?
Scott--
On Tue, Apr 10, 2012 at 1:22 PM, Liyu Yi wrote:
Awesome, You guys rock!
BTW, what will be the recommended mechanism for dependency wiring (or
DI). I know Spring will work, but somewhere I saw you guys are talking
about Guice.
Thanks again for the great job.
-- Liyu
> > > > > To post to this group, send email to play-framework@googlegroups.com
> > .
> > > > > To unsubscribe from this group, send email to
> > > > > play-framework+unsubscribe@googlegroups.com.
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/play-framework?hl=en.
>
> > > > --
> > > > Guillaume Bort
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "play-framework" group.
> > > > To post to this group, send email to play-framework@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/play-framework?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "play-framework" group.
> > To post to this group, send email to play-framework@googlegroups.com.
> > To unsubscribe from this group, send email to
> > For more options, visit this group at
> >http://groups.google.com/group/play-framework?hl=en.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
> > > > .
> > > > > > > To unsubscribe from this group, send email to
> > > > > > > play-framework+unsubscribe@googlegroups.com.
> > > > > > > For more options, visit this group at
> > > > > > >http://groups.google.com/group/play-framework?hl=en.
>
> > > > > > --
> > > > > > Guillaume Bort
>
> > > > > > --
> > > > > > You received this message because you are subscribed to the Google
> > > > Groups
> > > > > > "play-framework" group.
> > > > > > To post to this group, send email to
> > > > > > To unsubscribe from this group, send email to
> > > > > > play-framework+unsubscribe@googlegroups.com.
> > > > > > For more options, visit this group at
> > > > > >http://groups.google.com/group/play-framework?hl=en.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "play-framework" group.
> > > > To post to this group, send email to play-framework@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/play-framework?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "play-framework" group.
> > To post to this group, send email to play-framework@googlegroups.com.
> > To unsubscribe from this group, send email to
> > For more options, visit this group at
> >http://groups.google.com/group/play-framework?hl=en.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/YrfJQLHejO4J.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
To post to this group, send email to play-framework@googlegroups.com.
Everyone,
I have finished my version of the Spring Module for Play 2.0, it has documentation and is published in a maven repository. So it should be much easier to install now. I've added a documentation on how to use it, along with several sample applications which show how to use @annotation configuration, and illustrate Guillaume's example of injecting dependencies into controllers. I'm hoping to eventually submit this to the play repository when that's up and ready.
https://github.com/scott-phillips/Spring4Play2
Unfortunately, I wasn't aware of Will Sargents work until today. :( Our implementations are basically the same evolution of the original Play module except Will's is in Scala and mine is in Java.
Scott--
On Mon, Apr 9, 2012 at 11:19 PM, Will Sargent <will.s...@gmail.com> wrote:
On Fri, Apr 6, 2012 at 3:07 PM, Scott Phillips <sc...@scottphillips.com> wrote:
Everyone,
I've been playing around with the new version of Play for the past few days. I know Guillaume don't much care for Spring. However, we have several projects here that are Spring based and if we want to port them forward Spring support is needed. Plus I kind of like Spring :)
I've done a first pass at creating a Play 2.0 plugin that supports Spring. It's basically a repackaging of Nicolas' original spring module for Play 1.x. It basically works the same way as the original, except I haven't gotten component scanning to work yet. It is published on git hub:
https://github.com/scott-phillips/Spring4Play2
It's not published in a module/sbt/maven repository at present. That will follow in time.
Scott--
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/QvzdzgutuksJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.