How to access application configuration. Best practices/patterns

26 views
Skip to first unread message

jacob...@nexkey.com

unread,
Apr 25, 2017, 3:33:39 PM4/25/17
to Play Framework
I want to be able to access configuration variables within my controller classes in scala play 2.5. The use case is to be able to configure a cryptographic signing key that the server will use. What is the proper way to wire this together? I get from reading around that I am supposed to use Guice to inject the required configuration into my controller class, but I haven't found a fully wired example. Within the Guice module, how would I declare the correct implementation of the configuration class? 

I guess it would be something like this in the configure method of a class overriding AbstractModule 

bind(classOf[Configuration]).to XXX

What's the XXX? And am I going about this correctly in the first place? 

Thanks,
Jacob

Greg Methvin

unread,
Apr 25, 2017, 4:37:58 PM4/25/17
to play-framework
Why are you trying to bind Configuration? It's already bound by Play: https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/play/api/inject/BuiltinModule.scala#L40

All the Guice Play examples like https://github.com/playframework/play-scala-starter-example are already wired up. Take any injected class and add a Configuration to the constructor and you should be good.

--
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/ee30ff53-9d93-4934-8d12-e7d89be44893%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Tech Lead - Play Framework

Reply all
Reply to author
Forward
0 new messages