Skip to content
This repository was archived by the owner on Apr 23, 2019. It is now read-only.

[WIP] Simplify dagger modules#10

Merged
wsargent merged 5 commits intoplayframework:2.6.xfrom
wsargent:simplify-modules
May 2, 2017
Merged

[WIP] Simplify dagger modules#10
wsargent merged 5 commits intoplayframework:2.6.xfrom
wsargent:simplify-modules

Conversation

@wsargent
Copy link
Member

@wsargent wsargent commented Apr 28, 2017

Uses the built in components to leverage Play application.

Still isn't all the way through as the body parser is failing on injection.

UPDATE: Got the body parser to work, however there is still some global state being accessed:

[ERROR] [04/28/2017 21:06:51.458] [play-dev-mode-akka.actor.default-dispatcher-4] [akka.actor.ActorSystemImpl(play-dev-mode)] Internal server error, sending 500 response
java.lang.RuntimeException: The global application is disabled. Set play.allowGlobalApplication to allow global state here.
	at scala.sys.package$.error(package.scala:27)
	at play.api.Play$.privateMaybeApplication(Play.scala:86)
	at play.api.http.HttpConfiguration$.current(HttpConfiguration.scala:259)
	at play.api.mvc.Cookies$.config(Cookie.scala:139)
	at play.api.mvc.CookieHeaderEncoding.encodeSetCookieHeader(Cookie.scala:210)
	at play.api.mvc.CookieHeaderEncoding.encodeSetCookieHeader$(Cookie.scala:209)
	at play.api.mvc.Cookies$.encodeSetCookieHeader(Cookie.scala:136)
	at play.api.mvc.Result.bakeCookies(Results.scala:295)
	at play.core.server.common.ServerResultUtils.prepareCookies(ServerResultUtils.scala:229)
	at play.core.server.AkkaHttpServer.$anonfun$executeAction$3(AkkaHttpServer.scala:254)
	at akka.http.scaladsl.util.FastFuture$.strictTransform$1(FastFuture.scala:41)
	at akka.http.scaladsl.util.FastFuture$.transformWith$extension1(FastFuture.scala:55)
	at akka.http.scaladsl.util.FastFuture$.flatMap$extension(FastFuture.scala:26)
	at play.core.server.AkkaHttpServer.executeAction(AkkaHttpServer.scala:253)
	at play.core.server.AkkaHttpServer.executeHandler(AkkaHttpServer.scala:208)
	at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:155)
	at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$4(AkkaHttpServer.scala:90)

  /LICENSE:
    wrote /LICENSE
  **/plugins.sbt:
    addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.0-M5")
@wsargent wsargent changed the base branch from 2.5.x to 2.6.x April 28, 2017 23:55
@wsargent wsargent requested a review from marcospereira April 28, 2017 23:55
@Singleton
@Provides
public Clock providesClock() {
public Clock clock() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to demo the Clock injection though

@Override
public Application load(Context context) {
final ClassLoader classLoader = context.environment().classLoader();
final Optional<LoggerConfigurator> opt = LoggerConfigurator.fromClassLoader(classLoader);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put(play.api.i18n.Langs.class, langs);
}}));
}
extraMappings.put(JavaHandlerComponents.class, () -> new DefaultJavaHandlerComponents(simpleInjector.asScala(), actionCreator(), httpConfiguration(), executionContext(), javaContextComponents()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be solved by BuiltInComponentsFromContext itself.

/**
* A simple injector with additional classes...
*/
public class SimpleInjector implements Injector {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use the Scala SimpleInjector instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that's any better -- we have a java injector() method that would call out to a scala one, and then convert it back to java...

@wsargent wsargent merged commit df6d621 into playframework:2.6.x May 2, 2017
@wsargent wsargent deleted the simplify-modules branch May 2, 2017 22:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants