Wednesday 28 May 2014

Evaluating Play Framework 2.3 with Java 8

RTFM
Like many software libraries and frameworks, I have found that the best way to get the most out of Play is by putting some time towards reading the documentation.

For example, we wanted to evaluate how test friendly Play is, so we tried to figure out a mechanism for dependency injection of services into our controllers.

The sample code wasn't very helpful for this, as the controllers were implemented with static methods for each action, but thankfully the online documentation offered a section on dependency injection which showed how we can control the obtaining of a controller instance.

Scala bias
One aspect that was less than ideal is the slight Scala bias.  For example, the documentation that I found for dependency injection was titled ScalaDependencyInjection and only had sample code implemented in Scala.  Fortunately a lot of our team's existing codebase is already in Scala, so this hasn't proven to be a barrier.

Java 8
The main Java 8 specific feature that I have made use of so far is for calls to map from a WSResponse to something suitable for the controller to include in an HTTP response.

Thankfully the Play documentation includes sample code for Java pre and post version 8, so we can appreciate what the verbose version would have looked like while still in the process of getting our heads into lambdas and functional composition.

No comments:

Post a Comment