Reputation: 10523
I am migrating a (Scala) Play 2.3 app to 2.4. Previously I had a home-spun mechanism for building my Controller
objects, and provided them to Play using Global.getControllerInstance
. This is no longer available in 2.4. Is there a simple way to achieve the same effect? I'd rather not switch immediately to using Guice.
Upvotes: 2
Views: 910
Reputation: 693
One option would be to use a Guice Module facade to wrap your custom controller generator. You just need to write a single Guice class that will be used by Play to inject your custom generated instances, without any other changes.
Here is an example in Java. (Sorry, I do not have a scala example handy).
package com.example;
class ControllerProviderModule extends AbstractModule {
@Provides
MyController1 providesMyController1() {
// Create MyController1 and return it.
}
@Provides
MyController2 providesMyController2() {
// Create MyController2 and return it.
}
@Override
protected void configure() {
// Alternatively, use other approaches to bind controller classes to your custom generated instances
}
}
Add your module to Play.
play.modules.enabled += "com.example.ControllerProviderModule"
Upvotes: 1