diff --git a/core/play/src/main/scala/play/api/Application.scala b/core/play/src/main/scala/play/api/Application.scala index c9827ca415..e636024405 100644 --- a/core/play/src/main/scala/play/api/Application.scala +++ b/core/play/src/main/scala/play/api/Application.scala @@ -9,8 +9,6 @@ import java.io.* import akka.actor.ActorSystem import akka.actor.CoordinatedShutdown import akka.stream.Materializer -import javax.inject.Inject -import javax.inject.Singleton import play.api.http.* import play.api.inject.ApplicationLifecycle import play.api.internal.libs.concurrent.CoordinatedShutdownSupport @@ -110,8 +108,7 @@ trait Application: */ def stop(): Future[?] -@Singleton -class DefaultApplication @Inject() ( +class DefaultApplication( override val environment: Environment, applicationLifecycle: ApplicationLifecycle, override val configuration: Configuration, @@ -140,7 +137,7 @@ class DefaultApplication @Inject() ( errorHandler, actorSystem, materializer, - new CoordinatedShutdownProvider(actorSystem, applicationLifecycle).get + CoordinatedShutdownProvider.build(actorSystem, applicationLifecycle) ) override def path: File = environment.rootPath @@ -234,7 +231,7 @@ trait BuiltInComponents extends AkkaComponents with AkkaTypedComponents: coordinatedShutdown ) - lazy val cookieSigner: CookieSigner = new CookieSignerProvider(httpConfiguration.secret).get + lazy val cookieSigner: CookieSigner = new DefaultCookieSigner(httpConfiguration.secret) lazy val tempFileReaper: TemporaryFileReaper = new DefaultTemporaryFileReaper( @@ -244,9 +241,7 @@ trait BuiltInComponents extends AkkaComponents with AkkaTypedComponents: lazy val tempFileCreator: TemporaryFileCreator = new DefaultTemporaryFileCreator(applicationLifecycle, tempFileReaper, configuration) - lazy val fileMimeTypes: FileMimeTypes = new DefaultFileMimeTypesProvider( - httpConfiguration.fileMimeTypes - ).get + lazy val fileMimeTypes: FileMimeTypes = new DefaultFileMimeTypes(httpConfiguration.fileMimeTypes) // NOTE: the following helpers are declared as protected since they are only meant to be used inside BuiltInComponents // This also makes them not conflict with other methods of the same type when used with Macwire. diff --git a/core/play/src/main/scala/play/api/controllers/ExternalAssets.scala b/core/play/src/main/scala/play/api/controllers/ExternalAssets.scala index 9afcf92cf6..4ae2d44bdb 100644 --- a/core/play/src/main/scala/play/api/controllers/ExternalAssets.scala +++ b/core/play/src/main/scala/play/api/controllers/ExternalAssets.scala @@ -5,7 +5,6 @@ package controllers import java.io.* -import javax.inject.Inject import play.api.* import play.api.http.FileMimeTypes import play.api.mvc.* @@ -28,7 +27,7 @@ import scala.concurrent.Future * GET /assets/\uFEFF*file controllers.ExternalAssets.at(path="relativeToYourApp", file) * }}} */ -class ExternalAssets @Inject() (environment: Environment)(using +class ExternalAssets(environment: Environment)(using ec: ExecutionContext, fileMimeTypes: FileMimeTypes ) extends ControllerHelpers: diff --git a/core/play/src/main/scala/play/api/http/FileMimeTypes.scala b/core/play/src/main/scala/play/api/http/FileMimeTypes.scala index c271563bd4..75e58bf0df 100644 --- a/core/play/src/main/scala/play/api/http/FileMimeTypes.scala +++ b/core/play/src/main/scala/play/api/http/FileMimeTypes.scala @@ -5,9 +5,6 @@ package play.api.http import java.util.Locale -import javax.inject.Inject -import javax.inject.Provider -import javax.inject.Singleton import scala.annotation.implicitNotFound @@ -29,7 +26,7 @@ import scala.annotation.implicitNotFound * In a controller, an implicit FileMimeTypes object can either be defined explicitly: * * {{{ - * class MyController @Inject()(implicit val fileMimeTypes: FileMimeTypes) extends BaseController { + * class MyController(implicit val fileMimeTypes: FileMimeTypes) extends BaseController { * def sendFile() = ... * } * }}} @@ -38,7 +35,7 @@ import scala.annotation.implicitNotFound * available from [[play.api.mvc.ControllerComponents]], meaning that no explicit import is required: * * {{{ - * class MyController @Inject()(val controllerComponents: ControllerComponents) extends BaseController { + * class MyController(val controllerComponents: ControllerComponents) extends BaseController { * def sendFile() = ... * } * }}} @@ -58,15 +55,10 @@ trait FileMimeTypes: */ def forFileName(name: String): Option[String] -@Singleton -class DefaultFileMimeTypesProvider @Inject() (fileMimeTypesConfiguration: FileMimeTypesConfiguration) - extends Provider[FileMimeTypes]: - lazy val get = new DefaultFileMimeTypes(fileMimeTypesConfiguration) - /** * Default implementation of FileMimeTypes. */ -class DefaultFileMimeTypes @Inject() (config: FileMimeTypesConfiguration) extends FileMimeTypes: +class DefaultFileMimeTypes(config: FileMimeTypesConfiguration) extends FileMimeTypes: /** * Retrieves the usual MIME type for a given file name diff --git a/core/play/src/main/scala/play/api/http/HttpConfiguration.scala b/core/play/src/main/scala/play/api/http/HttpConfiguration.scala index 2cad5ea957..056f2c42d9 100644 --- a/core/play/src/main/scala/play/api/http/HttpConfiguration.scala +++ b/core/play/src/main/scala/play/api/http/HttpConfiguration.scala @@ -6,9 +6,6 @@ package play.api.http import com.typesafe.config.ConfigMemorySize -import javax.inject.Inject -import javax.inject.Provider -import javax.inject.Singleton import org.slf4j.LoggerFactory import play.api.* import play.api.libs.Codecs @@ -314,40 +311,3 @@ object HttpConfiguration: * For calling from Java. */ def createWithDefaults() = apply() - - @Singleton - class HttpConfigurationProvider @Inject() (configuration: Configuration, environment: Environment) - extends Provider[HttpConfiguration]: - lazy val get = fromConfiguration(configuration, environment) - - @Singleton - class ParserConfigurationProvider @Inject() (conf: HttpConfiguration) extends Provider[ParserConfiguration]: - lazy val get = conf.parser - - @Singleton - class CookiesConfigurationProvider @Inject() (conf: HttpConfiguration) - extends Provider[CookiesConfiguration]: - lazy val get = conf.cookies - - @Singleton - class SessionConfigurationProvider @Inject() (conf: HttpConfiguration) - extends Provider[SessionConfiguration]: - lazy val get = conf.session - - @Singleton - class FlashConfigurationProvider @Inject() (conf: HttpConfiguration) extends Provider[FlashConfiguration]: - lazy val get = conf.flash - - @Singleton - class ActionCompositionConfigurationProvider @Inject() (conf: HttpConfiguration) - extends Provider[ActionCompositionConfiguration]: - lazy val get = conf.actionComposition - - @Singleton - class FileMimeTypesConfigurationProvider @Inject() (conf: HttpConfiguration) - extends Provider[FileMimeTypesConfiguration]: - lazy val get = conf.fileMimeTypes - - @Singleton - class SecretConfigurationProvider @Inject() (conf: HttpConfiguration) extends Provider[SecretConfiguration]: - lazy val get: SecretConfiguration = conf.secret diff --git a/core/play/src/main/scala/play/api/http/HttpErrorHandler.scala b/core/play/src/main/scala/play/api/http/HttpErrorHandler.scala index ce7ad384e5..ec1fee9069 100644 --- a/core/play/src/main/scala/play/api/http/HttpErrorHandler.scala +++ b/core/play/src/main/scala/play/api/http/HttpErrorHandler.scala @@ -4,7 +4,6 @@ package play.api.http -import javax.inject.* import play.api.* import play.api.http.Status.* import play.api.libs.typedmap.TypedKey @@ -65,7 +64,6 @@ case class HttpErrorConfig(showDevErrors: Boolean = false, playEditor: Option[St * handler can't be found. This is a lazy parameter, to avoid circular dependency issues, since the router * may well depend on this. */ -@Singleton class DefaultHttpErrorHandler( config: HttpErrorConfig = HttpErrorConfig(), router: => Option[Router] = None @@ -90,14 +88,6 @@ class DefaultHttpErrorHandler( router ) - @Inject - def this( - environment: Environment, - configuration: Configuration, - router: Provider[Router] - ) = - this(environment, configuration, Some(router.get)) - /** * Invoked when a client error occurs, that is, an error in the 4xx series. * diff --git a/core/play/src/main/scala/play/api/http/HttpRequestHandler.scala b/core/play/src/main/scala/play/api/http/HttpRequestHandler.scala index 4863af5468..aede827d4f 100644 --- a/core/play/src/main/scala/play/api/http/HttpRequestHandler.scala +++ b/core/play/src/main/scala/play/api/http/HttpRequestHandler.scala @@ -4,9 +4,6 @@ package play.api.http -import javax.inject.Inject -import javax.inject.Provider - import play.api.http.Status.* import play.api.libs.streams.Accumulator import play.api.mvc.* @@ -51,14 +48,13 @@ object NotImplementedHttpRequestHandler extends HttpRequestHandler: * [[JavaCompatibleHttpRequestHandler]] is the default one, in order to provide support for Java actions. */ class DefaultHttpRequestHandler( - router: Provider[Router], + router: () => Router, errorHandler: HttpErrorHandler, configuration: HttpConfiguration, filters: Seq[EssentialFilter] ) extends HttpRequestHandler: - @Inject def this( - router: Provider[Router], + router: () => Router, errorHandler: HttpErrorHandler, configuration: HttpConfiguration, filters: HttpFilters @@ -169,4 +165,4 @@ class DefaultHttpRequestHandler( * A handler to handle the request, if one can be found */ def routeRequest(request: RequestHeader): Option[Handler] = - router.get().handlerFor(request) + router().handlerFor(request) diff --git a/core/play/src/main/scala/play/api/inject/ApplicationLifecycle.scala b/core/play/src/main/scala/play/api/inject/ApplicationLifecycle.scala index bc51f21314..8043fe810a 100644 --- a/core/play/src/main/scala/play/api/inject/ApplicationLifecycle.scala +++ b/core/play/src/main/scala/play/api/inject/ApplicationLifecycle.scala @@ -10,8 +10,6 @@ import java.util.concurrent.CompletionStage import java.util.concurrent.ConcurrentLinkedDeque import akka.Done -import javax.inject.Inject -import javax.inject.Singleton import play.api.Logger import scala.annotation.tailrec @@ -44,9 +42,8 @@ import scala.util.Try * * {{{ * import play.api.inject.ApplicationLifecycle - * import javax.inject.Inject * - * class SomeDatabase @Inject() (applicationLifecycle: ApplicationLifecycle) { + * class SomeDatabase(applicationLifecycle: ApplicationLifecycle) { * * private val connectionPool = new SomeConnectionPool() * applicationLifecycle.addStopHook { () => @@ -96,8 +93,7 @@ trait ApplicationLifecycle: /** * Default implementation of the application lifecycle. */ -@Singleton -class DefaultApplicationLifecycle @Inject() () extends ApplicationLifecycle: +class DefaultApplicationLifecycle() extends ApplicationLifecycle: private val logger = Logger(getClass) private val hooks = new ConcurrentLinkedDeque[() => Future[?]]() diff --git a/core/play/src/main/scala/play/api/libs/EventSource.scala b/core/play/src/main/scala/play/api/libs/EventSource.scala index ccd08a4944..b19cf06505 100644 --- a/core/play/src/main/scala/play/api/libs/EventSource.scala +++ b/core/play/src/main/scala/play/api/libs/EventSource.scala @@ -24,7 +24,6 @@ import play.api.libs.json.JsValue * {{{ * import java.time.ZonedDateTime * import java.time.format.DateTimeFormatter - * import javax.inject.Singleton * import akka.stream.scaladsl.Source * import play.api.http.ContentTypes * import play.api.libs.EventSource diff --git a/core/play/src/main/scala/play/api/libs/Files.scala b/core/play/src/main/scala/play/api/libs/Files.scala index 2a3b93d5c2..f575853a61 100644 --- a/core/play/src/main/scala/play/api/libs/Files.scala +++ b/core/play/src/main/scala/play/api/libs/Files.scala @@ -14,9 +14,6 @@ import java.time.Clock import java.time.Instant import java.util.stream -import javax.inject.Inject -import javax.inject.Provider -import javax.inject.Singleton import akka.actor.ActorSystem import akka.actor.Cancellable import com.google.common.base.FinalizablePhantomReference @@ -248,8 +245,7 @@ object Files: * application stop. Note that this will not clean up the filesystem if the application / JVM terminates * abnormally. */ - @Singleton - class DefaultTemporaryFileCreator @Inject() ( + class DefaultTemporaryFileCreator( applicationLifecycle: ApplicationLifecycle, temporaryFileReaper: TemporaryFileReaper, conf: Configuration @@ -335,8 +331,7 @@ object Files: trait TemporaryFileReaper: def updateTempFolder(folder: Path): Unit - @Singleton - class DefaultTemporaryFileReaper @Inject() ( + class DefaultTemporaryFileReaper( actorSystem: ActorSystem, config: TemporaryFileReaperConfiguration ) extends TemporaryFileReaper: @@ -448,21 +443,6 @@ object Files: */ def createWithDefaults() = apply() - @Singleton - @deprecated( - "On JDK8 and earlier, Class.getSimpleName on doubly nested Scala classes throws an exception. Use Files.TemporaryFileReaperConfigurationProvider instead. See https://github.com/scala/bug/issues/2034.", - "2.6.14" - ) - class TemporaryFileReaperConfigurationProvider @Inject() (configuration: Configuration) - extends Provider[TemporaryFileReaperConfiguration]: - lazy val get: TemporaryFileReaperConfiguration = fromConfiguration(configuration) - - @Singleton - class TemporaryFileReaperConfigurationProvider @Inject() (configuration: Configuration) - extends Provider[TemporaryFileReaperConfiguration]: - lazy val get: TemporaryFileReaperConfiguration = - TemporaryFileReaperConfiguration.fromConfiguration(configuration) - /** * Creates temporary folders using java.nio.file.Files.createTempFile. * diff --git a/core/play/src/main/scala/play/api/libs/concurrent/Akka.scala b/core/play/src/main/scala/play/api/libs/concurrent/Akka.scala index c90ead8f2e..24c4f35af8 100644 --- a/core/play/src/main/scala/play/api/libs/concurrent/Akka.scala +++ b/core/play/src/main/scala/play/api/libs/concurrent/Akka.scala @@ -15,9 +15,6 @@ import akka.actor.CoordinatedShutdown import akka.stream.Materializer import com.typesafe.config.Config import com.typesafe.config.ConfigValueFactory -import javax.inject.Inject -import javax.inject.Provider -import javax.inject.Singleton import org.slf4j.LoggerFactory import play.api.* import play.api.inject.ApplicationLifecycle @@ -38,15 +35,14 @@ trait AkkaComponents: @deprecated("Since Play 2.7.0 this is no longer required to create an ActorSystem.", "2.7.0") def applicationLifecycle: ApplicationLifecycle - lazy val actorSystem: ActorSystem = new ActorSystemProvider(environment, configuration).get + lazy val actorSystem: ActorSystem = + ActorSystemProvider.start(environment.classLoader, configuration, Nil*) - lazy val classicActorSystemProvider: ClassicActorSystemProvider = new ClassicActorSystemProviderProvider( - actorSystem - ).get + lazy val classicActorSystemProvider: ClassicActorSystemProvider = actorSystem @nowarn lazy val coordinatedShutdown: CoordinatedShutdown = - new CoordinatedShutdownProvider(actorSystem, applicationLifecycle).get + CoordinatedShutdownProvider.build(actorSystem, applicationLifecycle) implicit lazy val materializer: Materializer = Materializer.matFromSystem(using actorSystem) @@ -57,63 +53,17 @@ trait AkkaComponents: */ trait AkkaTypedComponents: def actorSystem: ActorSystem - implicit lazy val scheduler: Scheduler = new AkkaSchedulerProvider(actorSystem).get - -/** - * Provider for the actor system - */ -@Singleton -class ActorSystemProvider @Inject() (environment: Environment, configuration: Configuration) - extends Provider[ActorSystem]: - lazy val get: ActorSystem = ActorSystemProvider.start(environment.classLoader, configuration, Nil*) - -/** - * Provider for a classic actor system provide - */ -@Singleton -class ClassicActorSystemProviderProvider @Inject() (actorSystem: ActorSystem) - extends Provider[ClassicActorSystemProvider]: - lazy val get: ClassicActorSystemProvider = actorSystem - -/** - * Provider for an [[akka.actor.typed.Scheduler Akka Typed Scheduler]]. - */ -@Singleton -class AkkaSchedulerProvider @Inject() (actorSystem: ActorSystem) extends Provider[Scheduler]: - import akka.actor.typed.scaladsl.adapter.* - override lazy val get: Scheduler = actorSystem.scheduler.toTyped + implicit lazy val scheduler: Scheduler = + import akka.actor.typed.scaladsl.adapter.* + actorSystem.scheduler.toTyped object ActorSystemProvider: type StopHook = () => Future[?] - private val logger = LoggerFactory.getLogger(classOf[ActorSystemProvider]) + private val logger = LoggerFactory.getLogger("play.api.libs.concurrent.ActorSystemProvider") case object ApplicationShutdownReason extends CoordinatedShutdown.Reason - /** - * Start an ActorSystem, using the given configuration and ClassLoader. - * - * @return - * The ActorSystem and a function that can be used to stop it. - */ - @deprecated("Use start(ClassLoader, Configuration, Setup*) instead", "2.8.0") - protected[ActorSystemProvider] def start(classLoader: ClassLoader, config: Configuration): ActorSystem = - start(classLoader, config, Nil*) - - /** - * Start an ActorSystem, using the given configuration, ClassLoader, and additional ActorSystem Setup. - * - * @return - * The ActorSystem and a function that can be used to stop it. - */ - @deprecated("Use start(ClassLoader, Configuration, Setup*) instead", "2.8.0") - protected[ActorSystemProvider] def start( - classLoader: ClassLoader, - config: Configuration, - additionalSetup: Setup - ): ActorSystem = - start(classLoader, config, Seq(additionalSetup)*) - /** * Start an ActorSystem, using the given configuration, ClassLoader, and optional additional ActorSystem * Setups. @@ -159,22 +109,16 @@ object ActorSystemProvider: logger.debug(s"Starting application default Akka system: $name") ActorSystem(name, actorSystemSetup) -private object CoordinatedShutdownProvider: - private val logger = LoggerFactory.getLogger(classOf[CoordinatedShutdownProvider]) - -/** - * Provider for the coordinated shutdown - */ -@Singleton -class CoordinatedShutdownProvider @Inject() ( - actorSystem: ActorSystem, - applicationLifecycle: ApplicationLifecycle -) extends Provider[CoordinatedShutdown]: - import CoordinatedShutdownProvider.logger +private[play] object CoordinatedShutdownProvider: + private val logger = LoggerFactory.getLogger("play.api.libs.concurrent.CoordinatedShutdownProvider") + /** + * Build the [[CoordinatedShutdown]] for the given actor system, registering the application lifecycle stop + * hooks as a shutdown phase. + */ @nowarn // for applicationLifecycle.stop() - lazy val get: CoordinatedShutdown = - logWarningWhenRunPhaseConfigIsPresent() + def build(actorSystem: ActorSystem, applicationLifecycle: ApplicationLifecycle): CoordinatedShutdown = + logWarningWhenRunPhaseConfigIsPresent(actorSystem) implicit val ec = actorSystem.dispatcher @@ -188,7 +132,7 @@ class CoordinatedShutdownProvider @Inject() ( cs - private def logWarningWhenRunPhaseConfigIsPresent(): Unit = + private def logWarningWhenRunPhaseConfigIsPresent(actorSystem: ActorSystem): Unit = val config = actorSystem.settings.config if config.hasPath("play.akka.run-cs-from-phase") then logger.warn( diff --git a/core/play/src/main/scala/play/api/libs/concurrent/Futures.scala b/core/play/src/main/scala/play/api/libs/concurrent/Futures.scala index 70108b8450..ec4b352096 100644 --- a/core/play/src/main/scala/play/api/libs/concurrent/Futures.scala +++ b/core/play/src/main/scala/play/api/libs/concurrent/Futures.scala @@ -4,8 +4,6 @@ package play.api.libs.concurrent -import javax.inject.Inject - import akka.Done import akka.actor.ActorSystem @@ -21,7 +19,7 @@ import scala.language.implicitConversions * period of time: * * {{{ - * class MyService @Inject()(futures: Futures, piCalculator: PiCalculator) extends Timeout { + * class MyService(futures: Futures, piCalculator: PiCalculator) extends Timeout { * def calculateWithTimeout(timeoutDuration: FiniteDuration): Future[Int] = { * futures.timeout(timeoutDuration)(piCalculator.rawCalculation()) * } @@ -31,7 +29,7 @@ import scala.language.implicitConversions * And you can also use a delay to return data after a given period of time. * * {{{ - * class PiCalculator @Inject()(futures: Futures) { + * class PiCalculator(futures: Futures) { * def rawCalculation(): Future[Int] = { * futures.delay(300 millis) { Future.successful(42) } * } @@ -101,7 +99,7 @@ trait Futures: * @param actorSystem * the actor system to use. */ -class DefaultFutures @Inject() (actorSystem: ActorSystem) extends Futures: +class DefaultFutures(actorSystem: ActorSystem) extends Futures: override def timeout[A](timeoutDuration: FiniteDuration)(f: => Future[A]): Future[A] = implicit val ec = actorSystem.dispatchers.defaultGlobalDispatcher val timeoutFuture = akka.pattern.after(timeoutDuration, actorSystem.scheduler) { @@ -125,7 +123,7 @@ class DefaultFutures @Inject() (actorSystem: ActorSystem) extends Futures: * period of time: * * {{{ - * class MyService @Inject()(piCalculator: PiCalculator)(implicit futures: Futures) { + * class MyService(piCalculator: PiCalculator)(implicit futures: Futures) { * * def calculateWithTimeout(timeoutDuration: FiniteDuration): Future[Int] = { * piCalculator.rawCalculation().withTimeout(timeoutDuration) diff --git a/core/play/src/main/scala/play/api/libs/crypto/CookieSigner.scala b/core/play/src/main/scala/play/api/libs/crypto/CookieSigner.scala index 8e7cda6e68..c4f906dd6a 100644 --- a/core/play/src/main/scala/play/api/libs/crypto/CookieSigner.scala +++ b/core/play/src/main/scala/play/api/libs/crypto/CookieSigner.scala @@ -7,9 +7,6 @@ package play.api.libs.crypto import java.nio.charset.StandardCharsets import javax.crypto.Mac import javax.crypto.spec.SecretKeySpec -import javax.inject.Inject -import javax.inject.Provider -import javax.inject.Singleton import play.api.http.SecretConfiguration import play.api.libs.Codecs @@ -49,15 +46,10 @@ trait CookieSigner: */ def sign(message: String): String -@Singleton -class CookieSignerProvider @Inject() (secretConfiguration: SecretConfiguration) - extends Provider[CookieSigner]: - lazy val get: CookieSigner = new DefaultCookieSigner(secretConfiguration) - /** * Uses an HMAC-SHA1 for signing cookies. */ -class DefaultCookieSigner @Inject() (secretConfiguration: SecretConfiguration) extends CookieSigner: +class DefaultCookieSigner(secretConfiguration: SecretConfiguration) extends CookieSigner: private lazy val HmacSHA1 = "HmacSHA1" /** diff --git a/core/play/src/main/scala/play/api/mvc/Action.scala b/core/play/src/main/scala/play/api/mvc/Action.scala index fde344e08d..239d55956c 100644 --- a/core/play/src/main/scala/play/api/mvc/Action.scala +++ b/core/play/src/main/scala/play/api/mvc/Action.scala @@ -4,8 +4,6 @@ package play.api.mvc -import javax.inject.Inject - import akka.util.ByteString import play.api.* import play.api.libs.streams.Accumulator @@ -467,7 +465,6 @@ class ActionBuilderImpl[B](val parser: BodyParser[B])(using val executionContext class DefaultActionBuilderImpl(parser: BodyParser[AnyContent])(using ec: ExecutionContext) extends ActionBuilderImpl(parser) with DefaultActionBuilder: - @Inject def this(parser: BodyParsers.Default)(using ec: ExecutionContext) = this(parser: BodyParser[AnyContent]) /* NOTE: the following are all example uses of ActionFunction, each subtly diff --git a/core/play/src/main/scala/play/api/mvc/Binders.scala b/core/play/src/main/scala/play/api/mvc/Binders.scala index b61226960d..ff28574fa5 100644 --- a/core/play/src/main/scala/play/api/mvc/Binders.scala +++ b/core/play/src/main/scala/play/api/mvc/Binders.scala @@ -116,7 +116,7 @@ trait QueryStringBindable[A]: * // GET /show/:user controllers.Application.show(user) * // For example: /show/42 * - * class HomeController @Inject() (val controllerComponents: ControllerComponents) extends BaseController { + * class HomeController(val controllerComponents: ControllerComponents) extends BaseController { * def show(user: User) = Action { * ... * } diff --git a/core/play/src/main/scala/play/api/mvc/BodyParsers.scala b/core/play/src/main/scala/play/api/mvc/BodyParsers.scala index d5f64809cc..21a2ee4a2d 100644 --- a/core/play/src/main/scala/play/api/mvc/BodyParsers.scala +++ b/core/play/src/main/scala/play/api/mvc/BodyParsers.scala @@ -10,7 +10,6 @@ import java.nio.charset.* import java.nio.file.Files import java.util.Locale -import javax.inject.Inject import akka.stream.* import akka.stream.scaladsl.Flow import akka.stream.scaladsl.Sink @@ -389,7 +388,7 @@ object BodyParserUtils: .flatMap(clh => catching(classOf[NumberFormatException]).opt(clh.toLong)) .exists(_ > maxLength) -class DefaultPlayBodyParsers @Inject() ( +class DefaultPlayBodyParsers( val config: ParserConfiguration, val errorHandler: HttpErrorHandler, val materializer: Materializer, @@ -1117,7 +1116,7 @@ object BodyParsers: /** * The default body parser provided by Play */ - class Default @Inject() (parse: PlayBodyParsers) extends BodyParser[AnyContent]: + class Default(parse: PlayBodyParsers) extends BodyParser[AnyContent]: /** * An alternate constructor primarily designed for unit testing. Default values are set to empty or diff --git a/core/play/src/main/scala/play/api/mvc/Controller.scala b/core/play/src/main/scala/play/api/mvc/Controller.scala index 9e04715ce2..8cc809585a 100644 --- a/core/play/src/main/scala/play/api/mvc/Controller.scala +++ b/core/play/src/main/scala/play/api/mvc/Controller.scala @@ -4,7 +4,6 @@ package play.api.mvc -import javax.inject.Inject import play.api.data.FormBinding import play.api.http.* @@ -17,7 +16,7 @@ import scala.concurrent.ExecutionContext * helpers and useful constants. * * {{{ - * class MyController @Inject() (action: DefaultActionBuilder, parse: PlayBodyParsers) extends ControllerHelpers { + * class MyController(action: DefaultActionBuilder, parse: PlayBodyParsers) extends ControllerHelpers { * def index = action(parse.text) { * Ok * } @@ -125,7 +124,7 @@ trait RequestImplicits: * * For example: * {{{ - * class HomeController @Inject() (val controllerComponents: ControllerComponents) extends BaseController { + * class HomeController(val controllerComponents: ControllerComponents) extends BaseController { * * def hello(name:String) = Action { request => * Ok("Hello " + name) @@ -171,7 +170,6 @@ trait InjectedController extends BaseController: /** * Call this method to set the [[ControllerComponents]] instance. */ - @Inject def setControllerComponents(components: ControllerComponents): Unit = _components = components @@ -192,7 +190,7 @@ trait ControllerComponents: def fileMimeTypes: FileMimeTypes def executionContext: scala.concurrent.ExecutionContext -case class DefaultControllerComponents @Inject() ( +case class DefaultControllerComponents( actionBuilder: DefaultActionBuilder, parsers: PlayBodyParsers, fileMimeTypes: FileMimeTypes, diff --git a/core/play/src/main/scala/play/api/mvc/Cookie.scala b/core/play/src/main/scala/play/api/mvc/Cookie.scala index f94951a6ed..409041ee0c 100644 --- a/core/play/src/main/scala/play/api/mvc/Cookie.scala +++ b/core/play/src/main/scala/play/api/mvc/Cookie.scala @@ -7,7 +7,6 @@ package play.api.mvc import java.net.URLDecoder import java.net.URLEncoder import java.util.Locale -import javax.inject.Inject import play.api.MarkerContexts.SecurityMarkerContext import play.api.* @@ -315,7 +314,7 @@ trait CookieHeaderEncoding: /** * The default implementation of `CookieHeaders`. */ -class DefaultCookieHeaderEncoding @Inject() ( +class DefaultCookieHeaderEncoding( protected override val config: CookiesConfiguration = CookiesConfiguration() ) extends CookieHeaderEncoding diff --git a/core/play/src/main/scala/play/api/mvc/Flash.scala b/core/play/src/main/scala/play/api/mvc/Flash.scala index 5791977f69..a0f6aa630e 100644 --- a/core/play/src/main/scala/play/api/mvc/Flash.scala +++ b/core/play/src/main/scala/play/api/mvc/Flash.scala @@ -4,12 +4,10 @@ package play.api.mvc -import javax.inject.Inject - import play.api.http.FlashConfiguration import play.api.http.SecretConfiguration import play.api.libs.crypto.CookieSigner -import play.api.libs.crypto.CookieSignerProvider +import play.api.libs.crypto.DefaultCookieSigner /** * HTTP Flash scope. @@ -113,14 +111,14 @@ trait FlashCookieBaker extends CookieBaker[Flash] with CookieDataCodec: def serialize(flash: Flash): Map[String, String] = flash.data -class LegacyFlashCookieBaker @Inject() ( +class LegacyFlashCookieBaker( val config: FlashConfiguration, val secretConfiguration: SecretConfiguration, val cookieSigner: CookieSigner ) extends FlashCookieBaker with UrlEncodedCookieDataCodec: def this() = - this(FlashConfiguration(), SecretConfiguration(), new CookieSignerProvider(SecretConfiguration()).get) + this(FlashConfiguration(), SecretConfiguration(), new DefaultCookieSigner(SecretConfiguration())) object Flash: val emptyCookie = new Flash diff --git a/core/play/src/main/scala/play/api/mvc/Session.scala b/core/play/src/main/scala/play/api/mvc/Session.scala index 11f64d8880..15c9349683 100644 --- a/core/play/src/main/scala/play/api/mvc/Session.scala +++ b/core/play/src/main/scala/play/api/mvc/Session.scala @@ -4,12 +4,10 @@ package play.api.mvc -import javax.inject.Inject - import play.api.http.SecretConfiguration import play.api.http.SessionConfiguration import play.api.libs.crypto.CookieSigner -import play.api.libs.crypto.CookieSignerProvider +import play.api.libs.crypto.DefaultCookieSigner /** * HTTP Session. @@ -123,10 +121,10 @@ trait SessionCookieBaker extends CookieBaker[Session] with CookieDataCodec: * @param cookieSigner * the cookie signer, typically HMAC-SHA1 */ -class LegacySessionCookieBaker @Inject() (val config: SessionConfiguration, val cookieSigner: CookieSigner) +class LegacySessionCookieBaker(val config: SessionConfiguration, val cookieSigner: CookieSigner) extends SessionCookieBaker with UrlEncodedCookieDataCodec: - def this() = this(SessionConfiguration(), new CookieSignerProvider(SecretConfiguration()).get) + def this() = this(SessionConfiguration(), new DefaultCookieSigner(SecretConfiguration())) object Session: lazy val emptyCookie = new Session diff --git a/core/play/src/main/scala/play/api/mvc/package.scala b/core/play/src/main/scala/play/api/mvc/package.scala index 60f5c468cd..601b541411 100644 --- a/core/play/src/main/scala/play/api/mvc/package.scala +++ b/core/play/src/main/scala/play/api/mvc/package.scala @@ -9,7 +9,7 @@ package play.api * * For example, a typical controller: * {{{ - * class HomeController @Inject() (val controllerComponents: ControllerComponents) extends BaseController { + * class HomeController(val controllerComponents: ControllerComponents) extends BaseController { * * def index = Action { * Ok("It works!") diff --git a/core/play/src/main/scala/play/api/mvc/request/RequestFactory.scala b/core/play/src/main/scala/play/api/mvc/request/RequestFactory.scala index e802e45071..fbb765681b 100644 --- a/core/play/src/main/scala/play/api/mvc/request/RequestFactory.scala +++ b/core/play/src/main/scala/play/api/mvc/request/RequestFactory.scala @@ -4,10 +4,8 @@ package play.api.mvc.request -import javax.inject.Inject - import play.api.http.HttpConfiguration -import play.api.libs.crypto.CookieSignerProvider +import play.api.libs.crypto.DefaultCookieSigner import play.api.libs.typedmap.TypedMap import play.api.mvc.* @@ -80,15 +78,15 @@ object RequestFactory: * - session cookie * - flash cookie */ -class DefaultRequestFactory @Inject() ( +class DefaultRequestFactory( val cookieHeaderEncoding: CookieHeaderEncoding, val sessionBaker: SessionCookieBaker, val flashBaker: FlashCookieBaker ) extends RequestFactory: def this(config: HttpConfiguration) = this( new DefaultCookieHeaderEncoding(config.cookies), - new LegacySessionCookieBaker(config.session, new CookieSignerProvider(config.secret).get), - new LegacyFlashCookieBaker(config.flash, config.secret, new CookieSignerProvider(config.secret).get) + new LegacySessionCookieBaker(config.session, new DefaultCookieSigner(config.secret)), + new LegacyFlashCookieBaker(config.flash, config.secret, new DefaultCookieSigner(config.secret)) ) override def createRequestHeader( diff --git a/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/RoutesGenerator.scala b/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/RoutesGenerator.scala index bc6f94fd8a..b2e03608fc 100644 --- a/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/RoutesGenerator.scala +++ b/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/RoutesGenerator.scala @@ -122,8 +122,8 @@ object InjectedRoutesGenerator extends RoutesGenerator: .flatMap { case ((key @ (packageName, controller, instantiate), routes), index) => routes.headOption.map { route => val clazz = packageName.map(_ + ".").getOrElse("") + controller - // If it's using the @ syntax, we depend on the provider (ie, look it up each time) - val dep = if instantiate then s"javax.inject.Provider[$clazz]" else clazz + // If it's using the @ syntax, we depend on a factory (ie, look it up each time) + val dep = if instantiate then s"() => $clazz" else clazz val ident = controller + "_" + index key -> Dependency(ident, dep, route) diff --git a/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/templates/package.scala b/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/templates/package.scala index 0cfb9b7349..edcd069065 100644 --- a/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/templates/package.scala +++ b/dev-mode/routes-compiler/src/main/scala/play/routes/compiler/templates/package.scala @@ -57,7 +57,7 @@ package object templates: * Generate a controller method call for the given injected route */ def injectedControllerMethodCall(r: Route, ident: String, paramFormat: Parameter => String): String = - val methodPart = if r.call.instantiate then s"$ident.get.${r.call.method}" + val methodPart = if r.call.instantiate then s"$ident().${r.call.method}" else s"$ident.${r.call.method}" val paramPart = r.call.parameters .map { params => @@ -133,12 +133,6 @@ package object templates: if route.call.parameters.map(_.size).getOrElse(0) < 22 then tupleNames(route) else listNames(route) - /** - * The code to statically get the Play injector - */ - val Injector = - "play.api.Play.routesCompilerMaybeApplication.map(_.injector).getOrElse(play.api.inject.NewInstanceInjector)" - val scalaReservedWords = List( "abstract", "case", diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 4214f5de52..670fc91fee 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -35,7 +35,6 @@ object Dependencies { val guava = "com.google.guava" % "guava" % "33.6.0-jre" val findBugs = "com.google.code.findbugs" % "jsr305" % "3.0.2" // Needed by guava val mockitoAll = "org.mockito" % "mockito-core" % "4.11.0" - val javaxInject = "javax.inject" % "javax.inject" % "1" val scalaParserCombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % "2.4.0" @@ -53,7 +52,6 @@ object Dependencies { Seq( playJson, guava, - javaxInject, scalaXml, scalaParserCombinators ) ++ specs2Deps.map(_ % Test)