Create my own ActorSystem on play 2.5

45 views
Skip to first unread message

Tomer ben dror

unread,
Sep 25, 2016, 3:42:27 AM9/25/16
to Play Framework
Hi,

I have noticed this description on the official play documentation that there is the option to create my own ActorSystem for the play application

Could anyone describe  how to do it using Guice DI

Thanks, Tomer

Greg Methvin

unread,
Sep 25, 2016, 5:28:26 PM9/25/16
to play-framework
There are several ways to do it. Typically when you want to override bindings you can disable the Play-provided module and create your own module with the same bindings, so your configuration would look like:

play.modules.enabled += "com.example.FooModule"
play.modules.disabled += "play.FooModule"

The annoying thing here is that ActorSystem is in BuiltinModule, which has a ton of other bindings (see https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/play/api/inject/BuiltinModule.scala#L31). You'd have to repeat those bindings, or otherwise obtain them from BuiltinModule.

So another way is to extend the GuiceApplicationLoader and add an override:

class CustomApplicationLoader extends GuiceApplicationLoader() {
  override def overrides(context: Context) = super.overrides(context) ++ Seq(
    bind[ActorSystem].toProvider[CustomActorSystemProvider]
  )
}

The Seq of bindings is a Seq[GuiceableModule] so you can pass Guice modules instead of Play bindings too.

Greg

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/08170783-361c-4af4-a2f5-3c93d0dcb603%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Senior Software Engineer

Reply all
Reply to author
Forward
0 new messages