Last active
January 22, 2020 11:18
-
-
Save urcadox/dbddece71053b46754a2ee83d6ae3993 to your computer and use it in GitHub Desktop.
Creating an instance of a class with injected components in Play 2.5.x / 2.6.x / 2.7.x / 2.8.x REPL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For Play 2.5.x and 2.6.x | |
// After starting the application in the console (https://www.playframework.com/documentation/2.5.x/PlayConsole#launch-the-interactive-console) | |
import play.api._ | |
val env = Environment(new java.io.File("."), this.getClass.getClassLoader, Mode.Dev) | |
val context = ApplicationLoader.createContext(env) | |
val loader = ApplicationLoader(context) | |
val app = loader.load(context) | |
Play.start(app) | |
// Do this: | |
app.injector.instanceOf[full.path.YourClass](app.classloader.loadClass("full.path.YourClass").asInstanceOf[Class[full.path.YourClass]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For Play 2.7.x and 2.8.x | |
// After starting the application in the console https://www.playframework.com/documentation/2.8.x/PlayConsole#Launch-the-Scala-console) | |
import play.api._ | |
val env = Environment(new java.io.File("."), this.getClass.getClassLoader, Mode.Dev) | |
val context = ApplicationLoader.Context.create(env) | |
val loader = ApplicationLoader(context) | |
val app = loader.load(context) | |
Play.start(app) | |
// Do this: | |
app.injector.instanceOf[full.path.YourClass](app.classloader.loadClass("full.path.YourClass").asInstanceOf[Class[full.path.YourClass]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment